diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 15:10:37 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-12-19 15:10:37 +0300 |
commit | a4db97517ad095914c0652a07486ac607d99dab4 (patch) | |
tree | 58f57b42c52b1b4231cab44ef3934cbe55991d25 /qa | |
parent | 17295c75a1a28df78f719e0098dd31fe45ce0446 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'qa')
-rw-r--r-- | qa/qa/specs/helpers/fast_quarantine.rb | 70 | ||||
-rw-r--r-- | qa/qa/specs/spec_helper.rb | 7 | ||||
-rw-r--r-- | qa/spec/README.md | 8 | ||||
-rw-r--r-- | qa/spec/specs/helpers/fast_quarantine_spec.rb | 34 |
4 files changed, 114 insertions, 5 deletions
diff --git a/qa/qa/specs/helpers/fast_quarantine.rb b/qa/qa/specs/helpers/fast_quarantine.rb new file mode 100644 index 00000000000..5b72c82fa35 --- /dev/null +++ b/qa/qa/specs/helpers/fast_quarantine.rb @@ -0,0 +1,70 @@ +# frozen_string_literal: true + +module QA + module Specs + module Helpers + class FastQuarantine + include Support::API + + class << self + def configure! + return unless ENV["CI"] + return if ENV["FAST_QUARANTINE"] == "false" + return if ENV["CI_MERGE_REQUEST_LABELS"]&.include?("pipeline:run-flaky-tests") + + Runtime::Logger.debug("Running fast quarantine setup") + setup = new + setup.fetch_fq_file + setup.configure_rspec + rescue StandardError => e + Runtime::Logger.error("Failed to setup FastQuarantine, error: '#{e.class} - #{e.message}'") + end + end + + private_class_method :new + + def initialize + @logger = Runtime::Logger.logger + @fq_filename = "fast_quarantine-gitlab.txt" + end + + # Fetch and save fast quarantine file + # + # @return [void] + def fetch_fq_file + download_fast_quarantine + end + + # Configure rspec + # + # @return [void] + def configure_rspec + # Shared tooling that adds relevant rspec configuration + require_relative '../../../../spec/support/fast_quarantine' + end + + private + + attr_reader :logger, :fq_filename + + # Force path to be relative to ruby process in order to avoid issues when dealing with different execution + # contexts of qa docker container and CI runner environment + def fq_path + @fq_path ||= ENV["RSPEC_FAST_QUARANTINE_PATH"] = File.join(Runtime::Path.qa_root, "tmp", fq_filename) + end + + def download_fast_quarantine + logger.debug(" downloading fast quarantine file") + response = get( + "https://gitlab-org.gitlab.io/quality/engineering-productivity/fast-quarantine/rspec/#{fq_filename}", + verify_ssl: true + ) + raise "Failed to download fast quarantine file: #{response.code}" if response.code != HTTP_STATUS_OK + + logger.debug(" saving fast quarantine file to '#{fq_path}'") + File.write(fq_path, response.body) + end + end + end + end +end diff --git a/qa/qa/specs/spec_helper.rb b/qa/qa/specs/spec_helper.rb index d4295ce72e7..e585b660221 100644 --- a/qa/qa/specs/spec_helper.rb +++ b/qa/qa/specs/spec_helper.rb @@ -5,9 +5,6 @@ require 'factory_bot' require_relative '../../qa' -# Require shared test tooling from Rails test suite -require_relative '../../../spec/support/fast_quarantine' - QA::Specs::QaDeprecationToolkitEnv.configure! Knapsack::Adapters::RSpecAdapter.bind if QA::Runtime::Env.knapsack? @@ -16,10 +13,12 @@ Knapsack::Adapters::RSpecAdapter.bind if QA::Runtime::Env.knapsack? QA::Support::GitlabAddress.define_gitlab_address_attribute! QA::Runtime::Browser.configure! QA::Specs::Helpers::FeatureSetup.configure! +QA::Specs::Helpers::FastQuarantine.configure! QA::Runtime::AllureReport.configure! -QA::Runtime::Scenario.from_env(QA::Runtime::Env.runtime_scenario_attributes) QA::Service::DockerRun::Video.configure! +QA::Runtime::Scenario.from_env(QA::Runtime::Env.runtime_scenario_attributes) + # Enable zero monkey patching mode before loading any other RSpec code. RSpec.configure(&:disable_monkey_patching!) diff --git a/qa/spec/README.md b/qa/spec/README.md index b1fc38fb55d..0831ef4f052 100644 --- a/qa/spec/README.md +++ b/qa/spec/README.md @@ -1,7 +1,13 @@ # QA framework unit tests -To run framework unit tests, following command can be used: +To run all the unit tests under the framework, following command can be used: ```shell bundle exec rspec -O .rspec_internal ``` + +To run individual unit test, following command can be used: + +```shell +bundle exec rspec -O .rspec_internal spec/spec_path/file_spec.rb +``` diff --git a/qa/spec/specs/helpers/fast_quarantine_spec.rb b/qa/spec/specs/helpers/fast_quarantine_spec.rb new file mode 100644 index 00000000000..d63e5ef822e --- /dev/null +++ b/qa/spec/specs/helpers/fast_quarantine_spec.rb @@ -0,0 +1,34 @@ +# frozen_string_literal: true + +RSpec.describe QA::Specs::Helpers::FastQuarantine do + include QA::Support::Helpers::StubEnv + + let(:response) { instance_double(RestClient::Response, code: 200, body: fq_contents) } + let(:fq_path) { File.join(QA::Runtime::Path.qa_root, "tmp", "fast_quarantine-gitlab.txt") } + let(:fq_contents) { "fast_quarantine_contents" } + + before do + stub_env("CI", "true") + + allow(RSpec).to receive(:configure) + allow(File).to receive(:write).with(fq_path, fq_contents) + allow(RestClient::Request).to receive(:execute).and_return(response) + + # silence log messages during test execution + allow(QA::Runtime::Logger).to receive(:logger).and_return(instance_double(ActiveSupport::Logger, debug: nil)) + allow(QA::Runtime::Logger).to receive(:debug) + + described_class.configure! + end + + it "configures fast quarantine" do + expect(RSpec).to have_received(:configure) + expect(File).to have_received(:write).with(fq_path, fq_contents) + expect(RestClient::Request).to have_received(:execute).with( + cookies: {}, + method: :get, + url: "https://gitlab-org.gitlab.io/quality/engineering-productivity/fast-quarantine/rspec/fast_quarantine-gitlab.txt", + verify_ssl: true + ) + end +end |