summaryrefslogtreecommitdiff
path: root/qa
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2022-04-30 00:09:38 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2022-04-30 00:09:38 +0000
commit1f520d0c7af6a429e7bfb046a8c3ccc6920ef730 (patch)
tree3403e3689905fab48a13c321fedf7a0be3c2903f /qa
parentcb37aee9894007e60893693d5d48199ea0f0958f (diff)
downloadgitlab-ce-1f520d0c7af6a429e7bfb046a8c3ccc6920ef730.tar.gz
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'qa')
-rw-r--r--qa/.rspec5
-rw-r--r--qa/.rspec_internal2
-rw-r--r--qa/qa.rb1
-rw-r--r--qa/qa/scenario/template.rb51
-rw-r--r--qa/qa/scenario/test/integration/mattermost.rb6
-rw-r--r--qa/qa/specs/features/shared_contexts/merge_train_spec_with_user_prep.rb (renamed from qa/spec/support/shared_contexts/merge_train_spec_with_user_prep.rb)0
-rw-r--r--qa/qa/specs/features/shared_contexts/packages_registry_shared_context.rb (renamed from qa/spec/support/shared_contexts/packages_registry_shared_context.rb)0
-rw-r--r--qa/qa/specs/features/shared_contexts/variable_inheritance_shared_context.rb (renamed from qa/spec/support/shared_contexts/variable_inheritance_shared_context.rb)0
-rw-r--r--qa/qa/specs/features/shared_examples/merge_with_code_owner_shared_examples.rb (renamed from qa/spec/support/shared_examples/merge_with_code_owner_shared_examples.rb)0
-rw-r--r--qa/qa/specs/qa_deprecation_toolkit_env.rb (renamed from qa/spec/qa_deprecation_toolkit_env.rb)2
-rw-r--r--qa/qa/specs/spec_helper.rb136
-rw-r--r--qa/qa/support/gitlab_address.rb48
-rw-r--r--qa/qa/support/knapsack_report.rb (renamed from qa/qa/tools/knapsack_report.rb)24
-rw-r--r--qa/spec/README.md7
-rw-r--r--qa/spec/scenario/template_spec.rb9
-rw-r--r--qa/spec/scenario/test/integration/mattermost_spec.rb9
-rw-r--r--qa/spec/scenario_shared_examples.rb (renamed from qa/spec/specs/scenario_shared_examples.rb)0
-rw-r--r--qa/spec/spec_helper.rb132
-rw-r--r--qa/spec/specs/spec_helper.rb5
-rw-r--r--qa/tasks/knapsack.rake16
20 files changed, 250 insertions, 203 deletions
diff --git a/qa/.rspec b/qa/.rspec
index b83d9b7aa65..2f0b142df08 100644
--- a/qa/.rspec
+++ b/qa/.rspec
@@ -1,3 +1,6 @@
---color
+--force-color
+--order random
--format documentation
+--default-path qa/specs
--require spec_helper
+--tag ~orchestrated
diff --git a/qa/.rspec_internal b/qa/.rspec_internal
index ea32ca1e093..75786e123d4 100644
--- a/qa/.rspec_internal
+++ b/qa/.rspec_internal
@@ -1,4 +1,4 @@
--force-color
--order random
--format documentation
---require specs/spec_helper
+--require spec_helper
diff --git a/qa/qa.rb b/qa/qa.rb
index 73bcb6de637..01bf31f42f2 100644
--- a/qa/qa.rb
+++ b/qa/qa.rb
@@ -24,6 +24,7 @@ module QA
loader.push_dir(root, namespace: QA)
loader.ignore("#{root}/specs/features")
+ loader.ignore("#{root}/specs/spec_helper.rb")
loader.inflector.inflect(
"ce" => "CE",
diff --git a/qa/qa/scenario/template.rb b/qa/qa/scenario/template.rb
index 9cd9a6f438c..ad42202466d 100644
--- a/qa/qa/scenario/template.rb
+++ b/qa/qa/scenario/template.rb
@@ -21,14 +21,7 @@ module QA
end
def perform(options, *args)
- gitlab_address = extract_gitlab_address(options, args)
-
- # Define the "About" page as an `about` subdomain.
- # @example
- # Given *gitlab_address* = 'https://gitlab.com/' #=> https://about.gitlab.com/
- # Given *gitlab_address* = 'https://staging.gitlab.com/' #=> https://about.staging.gitlab.com/
- # Given *gitlab_address* = 'http://gitlab-abc123.test/' #=> http://about.gitlab-abc123.test/
- Runtime::Scenario.define(:about_address, gitlab_address.tap { |add| add.host = "about.#{add.host}" }.to_s)
+ define_gitlab_address(options, args)
# Save the scenario class name
Runtime::Scenario.define(:klass, self.class.name)
@@ -36,7 +29,7 @@ module QA
##
# Setup knapsack and download latest report
#
- Tools::KnapsackReport.configure! if Runtime::Env.knapsack?
+ Support::KnapsackReport.configure!
##
# Perform before hooks, which are different for CE and EE
@@ -70,32 +63,22 @@ module QA
private
- # For backwards-compatibility, if the gitlab instance address is not
- # specified as an option parsed by OptionParser, it can be specified as
- # the first argument
- def extract_gitlab_address(options, args)
- opt_name = :gitlab_address
- address_from_opt = Runtime::Scenario.attributes[opt_name]
- # return gitlab address if it was set via named option already
- return validate_address(opt_name, address_from_opt) && URI(address_from_opt) if address_from_opt
-
- address = if args.first.nil? || File.exist?(args.first)
- # if first arg is a valid path and not address, it's a spec file, default to environment variable
- Runtime::Env.gitlab_url
- else
- args.shift
- end
-
- validate_address(opt_name, address)
- Runtime::Scenario.define(opt_name, address)
-
- URI(address)
- end
+ delegate :define_gitlab_address_attribute!, to: 'QA::Support::GitlabAddress'
+
+ # Define gitlab address attribute
+ #
+ # Use first argument if a valid address, else use named argument or default to environment variable
+ #
+ # @param [Hash] options
+ # @param [Array] args
+ # @return [void]
+ def define_gitlab_address(options, args)
+ address_from_opt = Runtime::Scenario.attributes[:gitlab_address]
+
+ return define_gitlab_address_attribute!(args.shift) if args.first && Runtime::Address.valid?(args.first)
+ return define_gitlab_address_attribute!(address_from_opt) if address_from_opt
- def validate_address(name, address)
- Runtime::Address.valid?(address) || raise(
- ::ArgumentError, "Configured address parameter '#{name}' is not a valid url: #{address}"
- )
+ define_gitlab_address_attribute!
end
end
end
diff --git a/qa/qa/scenario/test/integration/mattermost.rb b/qa/qa/scenario/test/integration/mattermost.rb
index 4b1498faa37..145c767a38c 100644
--- a/qa/qa/scenario/test/integration/mattermost.rb
+++ b/qa/qa/scenario/test/integration/mattermost.rb
@@ -12,12 +12,6 @@ module QA
tags :mattermost
attribute :mattermost_address, '--mattermost-address URL', 'Address of the Mattermost server'
-
- def perform(options, *args)
- extract_address(:mattermost_address, options)
-
- super(options, *args)
- end
end
end
end
diff --git a/qa/spec/support/shared_contexts/merge_train_spec_with_user_prep.rb b/qa/qa/specs/features/shared_contexts/merge_train_spec_with_user_prep.rb
index 9d1a37cb0b8..9d1a37cb0b8 100644
--- a/qa/spec/support/shared_contexts/merge_train_spec_with_user_prep.rb
+++ b/qa/qa/specs/features/shared_contexts/merge_train_spec_with_user_prep.rb
diff --git a/qa/spec/support/shared_contexts/packages_registry_shared_context.rb b/qa/qa/specs/features/shared_contexts/packages_registry_shared_context.rb
index 73a6c2bd99e..73a6c2bd99e 100644
--- a/qa/spec/support/shared_contexts/packages_registry_shared_context.rb
+++ b/qa/qa/specs/features/shared_contexts/packages_registry_shared_context.rb
diff --git a/qa/spec/support/shared_contexts/variable_inheritance_shared_context.rb b/qa/qa/specs/features/shared_contexts/variable_inheritance_shared_context.rb
index 1dc8870d4d9..1dc8870d4d9 100644
--- a/qa/spec/support/shared_contexts/variable_inheritance_shared_context.rb
+++ b/qa/qa/specs/features/shared_contexts/variable_inheritance_shared_context.rb
diff --git a/qa/spec/support/shared_examples/merge_with_code_owner_shared_examples.rb b/qa/qa/specs/features/shared_examples/merge_with_code_owner_shared_examples.rb
index 4bbad9bf3e5..4bbad9bf3e5 100644
--- a/qa/spec/support/shared_examples/merge_with_code_owner_shared_examples.rb
+++ b/qa/qa/specs/features/shared_examples/merge_with_code_owner_shared_examples.rb
diff --git a/qa/spec/qa_deprecation_toolkit_env.rb b/qa/qa/specs/qa_deprecation_toolkit_env.rb
index 2a21961d89e..21ef5a6f229 100644
--- a/qa/spec/qa_deprecation_toolkit_env.rb
+++ b/qa/qa/specs/qa_deprecation_toolkit_env.rb
@@ -7,9 +7,11 @@ require 'active_support/gem_version'
module QaDeprecationToolkitEnv
# Taken from https://github.com/jeremyevans/ruby-warning/blob/1.1.0/lib/warning.rb#L18
+ # rubocop:disable Layout/LineLength
def self.kwargs_warning
%r{warning: (?:Using the last argument (?:for `.+' )?as keyword parameters is deprecated; maybe \*\* should be added to the call|Passing the keyword argument (?:for `.+' )?as the last hash parameter is deprecated|Splitting the last argument (?:for `.+' )?into positional and keyword parameters is deprecated|The called method (?:`.+' )?is defined here)\n\z}
end
+ # rubocop:enable Layout/LineLength
def self.configure!
# Enable ruby deprecations for keywords, it's suppressed by default in Ruby 2.7
diff --git a/qa/qa/specs/spec_helper.rb b/qa/qa/specs/spec_helper.rb
new file mode 100644
index 00000000000..b130fff0488
--- /dev/null
+++ b/qa/qa/specs/spec_helper.rb
@@ -0,0 +1,136 @@
+# frozen_string_literal: true
+
+require_relative '../../qa'
+
+require_relative 'qa_deprecation_toolkit_env'
+QaDeprecationToolkitEnv.configure!
+
+Knapsack::Adapters::RSpecAdapter.bind if QA::Runtime::Env.knapsack?
+
+QA::Support::GitlabAddress.define_gitlab_address_attribute!
+QA::Runtime::Browser.configure! unless QA::Runtime::Env.dry_run
+QA::Runtime::AllureReport.configure!
+QA::Runtime::Scenario.from_env(QA::Runtime::Env.runtime_scenario_attributes)
+
+Dir[::File.join(__dir__, "features/shared_examples/*.rb")].sort.each { |f| require f }
+Dir[::File.join(__dir__, "features/shared_contexts/*.rb")].sort.each { |f| require f }
+
+RSpec.configure do |config|
+ config.include QA::Support::Matchers::EventuallyMatcher
+ config.include QA::Support::Matchers::HaveMatcher
+
+ config.add_formatter QA::Support::Formatters::ContextFormatter
+ config.add_formatter QA::Support::Formatters::QuarantineFormatter
+ config.add_formatter QA::Support::Formatters::FeatureFlagFormatter
+ config.add_formatter QA::Support::Formatters::TestStatsFormatter if QA::Runtime::Env.export_metrics?
+
+ config.before(:suite) do |suite|
+ QA::Resource::ReusableCollection.register_resource_classes do |collection|
+ QA::Resource::ReusableProject.register(collection)
+ QA::Resource::ReusableGroup.register(collection)
+ end
+ end
+
+ config.prepend_before do |example|
+ QA::Runtime::Logger.info("Starting test: #{Rainbow(example.full_description).bright}")
+ QA::Runtime::Example.current = example
+
+ # Reset fabrication counters tracked in resource base
+ Thread.current[:api_fabrication] = 0
+ Thread.current[:browser_ui_fabrication] = 0
+ end
+
+ config.after do
+ # If a .netrc file was created during the test, delete it so that subsequent tests don't try to use the same logins
+ QA::Git::Repository.new.delete_netrc
+ end
+
+ # Add fabrication time to spec metadata
+ config.append_after do |example|
+ example.metadata[:api_fabrication] = Thread.current[:api_fabrication]
+ example.metadata[:browser_ui_fabrication] = Thread.current[:browser_ui_fabrication]
+ end
+
+ config.after(:context) do
+ if !QA::Runtime::Browser.blank_page? && QA::Page::Main::Menu.perform(&:signed_in?)
+ QA::Page::Main::Menu.perform(&:sign_out)
+ raise(
+ <<~ERROR
+ The test left the browser signed in.
+
+ Usually, Capybara prevents this from happening but some things can
+ interfere. For example, if it has an `after(:context)` block that logs
+ in, the browser will stay logged in and this will cause the next test
+ to fail.
+
+ Please make sure the test does not leave the browser signed in.
+ ERROR
+ )
+ end
+ end
+
+ config.after(:suite) do |suite|
+ # Write all test created resources to JSON file
+ QA::Tools::TestResourceDataProcessor.write_to_file(suite.reporter.failed_examples.any?)
+
+ # If requested, confirm that resources were used appropriately (e.g., not left with changes that interfere with
+ # further reuse)
+ QA::Resource::ReusableCollection.validate_resource_reuse if QA::Runtime::Env.validate_resource_reuse?
+
+ # If any tests failed, leave the resources behind to help troubleshoot, otherwise remove them.
+ # Do not remove the shared resource on live environments
+ begin
+ next if suite.reporter.failed_examples.present?
+ next unless QA::Runtime::Scenario.attributes.include?(:gitlab_address)
+ next if QA::Runtime::Env.running_on_dot_com?
+
+ QA::Resource::ReusableCollection.remove_all_via_api!
+ rescue QA::Resource::Errors::InternalServerError => e
+ # Temporarily prevent this error from failing jobs while the cause is investigated
+ # See https://gitlab.com/gitlab-org/gitlab/-/issues/354387
+ QA::Runtime::Logger.debug(e.message)
+ end
+ end
+
+ config.append_after(:suite) do
+ QA::Support::KnapsackReport.move_regenerated_report if QA::Runtime::Env.knapsack?
+ end
+
+ config.expect_with :rspec do |expectations|
+ expectations.include_chain_clauses_in_custom_matcher_descriptions = true
+ end
+
+ config.mock_with :rspec do |mocks|
+ mocks.verify_partial_doubles = true
+ end
+
+ config.shared_context_metadata_behavior = :apply_to_host_groups
+ config.disable_monkey_patching!
+ config.expose_dsl_globally = true
+ config.profile_examples = 10
+ config.order = :random
+ Kernel.srand config.seed
+
+ # This option allows to use shorthand aliases for adding :focus metadata - fit, fdescribe and fcontext
+ config.filter_run_when_matching :focus
+
+ if ENV['CI'] && !QA::Runtime::Env.disable_rspec_retry?
+ # show retry status in spec process
+ config.verbose_retry = true
+
+ # show exception that triggers a retry if verbose_retry is set to true
+ config.display_try_failure_messages = true
+
+ non_quarantine_retries = QA::Runtime::Env.ci_project_name =~ /staging|canary|production/ ? 3 : 2
+ config.around do |example|
+ quarantine = example.metadata[:quarantine]
+ different_quarantine_context = QA::Specs::Helpers::Quarantine.quarantined_different_context?(quarantine)
+ focused_quarantine = QA::Specs::Helpers::Quarantine.filters.key?(:quarantine)
+
+ # Do not disable retry when spec is quarantined but on different environment
+ next example.run_with_retry(retry: non_quarantine_retries) if different_quarantine_context && !focused_quarantine
+
+ example.run_with_retry(retry: quarantine ? 1 : non_quarantine_retries)
+ end
+ end
+end
diff --git a/qa/qa/support/gitlab_address.rb b/qa/qa/support/gitlab_address.rb
new file mode 100644
index 00000000000..d978bb2eee5
--- /dev/null
+++ b/qa/qa/support/gitlab_address.rb
@@ -0,0 +1,48 @@
+# frozen_string_literal: true
+
+module QA
+ module Support
+ class GitlabAddress
+ class << self
+ # Define gitlab address
+ #
+ # @param [String] address
+ # @return [void]
+ def define_gitlab_address_attribute!(address = Runtime::Env.gitlab_url)
+ return if initialized?
+
+ validate_address(address)
+
+ Runtime::Scenario.define(:gitlab_address, address)
+ # Define the "About" page as an `about` subdomain.
+ # @example
+ # Given *gitlab_address* = 'https://gitlab.com/' #=> https://about.gitlab.com/
+ # Given *gitlab_address* = 'https://staging.gitlab.com/' #=> https://about.staging.gitlab.com/
+ # Given *gitlab_address* = 'http://gitlab-abc123.test/' #=> http://about.gitlab-abc123.test/
+ Runtime::Scenario.define(:about_address, URI(address).tap { |uri| uri.host = "about.#{uri.host}" }.to_s)
+
+ @initialized = true
+ end
+
+ private
+
+ # Gitlab address already set up
+ #
+ # @return [Boolean]
+ def initialized?
+ @initialized
+ end
+
+ # Validate if address is a valid url
+ #
+ # @param [String] address
+ # @return [void]
+ def validate_address(address)
+ Runtime::Address.valid?(address) || raise(
+ ::ArgumentError, "Configured gitlab address is not a valid url: #{address}"
+ )
+ end
+ end
+ end
+ end
+end
diff --git a/qa/qa/tools/knapsack_report.rb b/qa/qa/support/knapsack_report.rb
index e50c4fe63d2..0ec53461e3f 100644
--- a/qa/qa/tools/knapsack_report.rb
+++ b/qa/qa/support/knapsack_report.rb
@@ -3,7 +3,7 @@
require "fog/google"
module QA
- module Tools
+ module Support
class KnapsackReport
extend SingleForwardable
@@ -20,11 +20,10 @@ module QA
#
# @return [void]
def configure!
- ENV["KNAPSACK_TEST_FILE_PATTERN"] ||= "qa/specs/features/**/*_spec.rb"
- ENV["KNAPSACK_REPORT_PATH"] = report_path
-
- Knapsack.logger = QA::Runtime::Logger.logger
+ return unless QA::Runtime::Env.knapsack?
+ setup_logger!
+ setup_environment!
download_report
end
@@ -89,6 +88,21 @@ module QA
private
+ # Setup knapsack logger
+ #
+ # @return [void]
+ def setup_logger!
+ Knapsack.logger = QA::Runtime::Logger.logger
+ end
+
+ # Set knapsack environment variables
+ #
+ # @return [void]
+ def setup_environment!
+ ENV["KNAPSACK_TEST_FILE_PATTERN"] ||= "qa/specs/features/**/*_spec.rb"
+ ENV["KNAPSACK_REPORT_PATH"] = report_path
+ end
+
# Logger instance
#
# @return [Logger]
diff --git a/qa/spec/README.md b/qa/spec/README.md
new file mode 100644
index 00000000000..b1fc38fb55d
--- /dev/null
+++ b/qa/spec/README.md
@@ -0,0 +1,7 @@
+# QA framework unit tests
+
+To run framework unit tests, following command can be used:
+
+```shell
+bundle exec rspec -O .rspec_internal
+```
diff --git a/qa/spec/scenario/template_spec.rb b/qa/spec/scenario/template_spec.rb
index 2b8a00141e4..51cdab5de22 100644
--- a/qa/spec/scenario/template_spec.rb
+++ b/qa/spec/scenario/template_spec.rb
@@ -20,6 +20,8 @@ RSpec.describe QA::Scenario::Template do
allow(scenario).to receive(:attributes).and_return({ gitlab_address: gitlab_address })
allow(scenario).to receive(:define)
+
+ QA::Support::GitlabAddress.instance_variable_set(:@initialized, false)
end
it 'allows a feature to be enabled' do
@@ -95,13 +97,6 @@ RSpec.describe QA::Scenario::Template do
expect(scenario).to have_received(:define).with(:gitlab_address, gitlab_address_from_env)
end
- it 'defines only about address' do
- subject.perform({ gitlab_address: gitlab_address })
-
- expect(scenario).not_to have_received(:define).with(:gitlab_address, gitlab_address)
- expect(scenario).to have_received(:define).with(:about_address, 'https://about.gitlab.com/')
- end
-
it 'defines klass attribute' do
subject.perform({ gitlab_address: gitlab_address })
diff --git a/qa/spec/scenario/test/integration/mattermost_spec.rb b/qa/spec/scenario/test/integration/mattermost_spec.rb
index 20a85598463..4cdd0c0cb0e 100644
--- a/qa/spec/scenario/test/integration/mattermost_spec.rb
+++ b/qa/spec/scenario/test/integration/mattermost_spec.rb
@@ -3,17 +3,10 @@
RSpec.describe QA::Scenario::Test::Integration::Mattermost do
describe '#perform' do
it_behaves_like 'a QA scenario class' do
- let(:args) { { gitlab_address: 'http://gitlab_address', mattermost_address: 'http://mattermost_address' } }
+ let(:args) { { gitlab_address: 'http://gitlab_address' } }
let(:named_options) { %w[--address http://gitlab_address --mattermost-address http://mattermost_address] }
let(:tags) { [:mattermost] }
let(:options) { ['path1'] }
-
- it 'defines mattermost address' do
- subject.perform(args)
-
- expect(scenario).to have_received(:define)
- .with(:mattermost_address, 'http://mattermost_address')
- end
end
end
end
diff --git a/qa/spec/specs/scenario_shared_examples.rb b/qa/spec/scenario_shared_examples.rb
index 55aae731cd9..55aae731cd9 100644
--- a/qa/spec/specs/scenario_shared_examples.rb
+++ b/qa/spec/scenario_shared_examples.rb
diff --git a/qa/spec/spec_helper.rb b/qa/spec/spec_helper.rb
index b81c41bb79c..95970800a4e 100644
--- a/qa/spec/spec_helper.rb
+++ b/qa/spec/spec_helper.rb
@@ -2,134 +2,4 @@
require_relative '../qa'
-require_relative 'qa_deprecation_toolkit_env'
-QaDeprecationToolkitEnv.configure!
-
-Knapsack::Adapters::RSpecAdapter.bind if QA::Runtime::Env.knapsack?
-
-QA::Runtime::Browser.configure! unless QA::Runtime::Env.dry_run
-QA::Runtime::AllureReport.configure!
-QA::Runtime::Scenario.from_env(QA::Runtime::Env.runtime_scenario_attributes)
-
-Dir[::File.join(__dir__, "support/shared_examples/*.rb")].sort.each { |f| require f }
-Dir[::File.join(__dir__, "support/shared_contexts/*.rb")].sort.each { |f| require f }
-
-RSpec.configure do |config|
- config.include QA::Support::Matchers::EventuallyMatcher
- config.include QA::Support::Matchers::HaveMatcher
-
- config.add_formatter QA::Support::Formatters::ContextFormatter
- config.add_formatter QA::Support::Formatters::QuarantineFormatter
- config.add_formatter QA::Support::Formatters::FeatureFlagFormatter
- config.add_formatter QA::Support::Formatters::TestStatsFormatter if QA::Runtime::Env.export_metrics?
-
- config.before(:suite) do |suite|
- QA::Resource::ReusableCollection.register_resource_classes do |collection|
- QA::Resource::ReusableProject.register(collection)
- QA::Resource::ReusableGroup.register(collection)
- end
- end
-
- config.prepend_before do |example|
- QA::Runtime::Logger.info("Starting test: #{Rainbow(example.full_description).bright}")
- QA::Runtime::Example.current = example
-
- # Reset fabrication counters tracked in resource base
- Thread.current[:api_fabrication] = 0
- Thread.current[:browser_ui_fabrication] = 0
- end
-
- config.after do
- # If a .netrc file was created during the test, delete it so that subsequent tests don't try to use the same logins
- QA::Git::Repository.new.delete_netrc
- end
-
- # Add fabrication time to spec metadata
- config.append_after do |example|
- example.metadata[:api_fabrication] = Thread.current[:api_fabrication]
- example.metadata[:browser_ui_fabrication] = Thread.current[:browser_ui_fabrication]
- end
-
- config.after(:context) do
- if !QA::Runtime::Browser.blank_page? && QA::Page::Main::Menu.perform(&:signed_in?)
- QA::Page::Main::Menu.perform(&:sign_out)
- raise(
- <<~ERROR
- The test left the browser signed in.
-
- Usually, Capybara prevents this from happening but some things can
- interfere. For example, if it has an `after(:context)` block that logs
- in, the browser will stay logged in and this will cause the next test
- to fail.
-
- Please make sure the test does not leave the browser signed in.
- ERROR
- )
- end
- end
-
- config.after(:suite) do |suite|
- # Write all test created resources to JSON file
- QA::Tools::TestResourceDataProcessor.write_to_file(suite.reporter.failed_examples.any?)
-
- # If requested, confirm that resources were used appropriately (e.g., not left with changes that interfere with
- # further reuse)
- QA::Resource::ReusableCollection.validate_resource_reuse if QA::Runtime::Env.validate_resource_reuse?
-
- # If any tests failed, leave the resources behind to help troubleshoot, otherwise remove them.
- # Do not remove the shared resource on live environments
- begin
- next if suite.reporter.failed_examples.present?
- next unless QA::Runtime::Scenario.attributes.include?(:gitlab_address)
- next if QA::Runtime::Env.running_on_dot_com?
-
- QA::Resource::ReusableCollection.remove_all_via_api!
- rescue QA::Resource::Errors::InternalServerError => e
- # Temporarily prevent this error from failing jobs while the cause is investigated
- # See https://gitlab.com/gitlab-org/gitlab/-/issues/354387
- QA::Runtime::Logger.debug(e.message)
- end
- end
-
- config.append_after(:suite) do
- QA::Tools::KnapsackReport.move_regenerated_report if QA::Runtime::Env.knapsack?
- end
-
- config.expect_with :rspec do |expectations|
- expectations.include_chain_clauses_in_custom_matcher_descriptions = true
- end
-
- config.mock_with :rspec do |mocks|
- mocks.verify_partial_doubles = true
- end
-
- config.shared_context_metadata_behavior = :apply_to_host_groups
- config.disable_monkey_patching!
- config.expose_dsl_globally = true
- config.profile_examples = 10
- config.order = :random
- Kernel.srand config.seed
-
- # show retry status in spec process
- config.verbose_retry = true
-
- # show exception that triggers a retry if verbose_retry is set to true
- config.display_try_failure_messages = true
-
- # This option allows to use shorthand aliases for adding :focus metadata - fit, fdescribe and fcontext
- config.filter_run_when_matching :focus
-
- if ENV['CI'] && !QA::Runtime::Env.disable_rspec_retry?
- non_quarantine_retries = QA::Runtime::Env.ci_project_name =~ /staging|canary|production/ ? 3 : 2
- config.around do |example|
- quarantine = example.metadata[:quarantine]
- different_quarantine_context = QA::Specs::Helpers::Quarantine.quarantined_different_context?(quarantine)
- focused_quarantine = QA::Specs::Helpers::Quarantine.filters.key?(:quarantine)
-
- # Do not disable retry when spec is quarantined but on different environment
- next example.run_with_retry(retry: non_quarantine_retries) if different_quarantine_context && !focused_quarantine
-
- example.run_with_retry(retry: quarantine ? 1 : non_quarantine_retries)
- end
- end
-end
+require_relative 'scenario_shared_examples'
diff --git a/qa/spec/specs/spec_helper.rb b/qa/spec/specs/spec_helper.rb
deleted file mode 100644
index e4514c6c64f..00000000000
--- a/qa/spec/specs/spec_helper.rb
+++ /dev/null
@@ -1,5 +0,0 @@
-# frozen_string_literal: true
-
-require_relative '../../qa'
-
-require_relative 'scenario_shared_examples'
diff --git a/qa/tasks/knapsack.rake b/qa/tasks/knapsack.rake
index ce4a1679bd1..c3a2deab7f3 100644
--- a/qa/tasks/knapsack.rake
+++ b/qa/tasks/knapsack.rake
@@ -1,20 +1,26 @@
# frozen_string_literal: true
-# rubocop:disable Rails/RakeEnvironment
namespace :knapsack do
+ desc "Run tests with knapsack runner"
+ task :rspec, [:rspec_args] do |_, args|
+ raise "This environment is not compatible with knapsack runner!" unless QA::Runtime::Env.knapsack?
+
+ QA::Support::KnapsackReport.configure!
+ Knapsack::Runners::RSpecRunner.run(args[:rspec_args])
+ end
+
desc "Download latest knapsack report"
task :download do
- QA::Tools::KnapsackReport.download
+ QA::Support::KnapsackReport.download
end
desc "Merge and upload knapsack report"
task :upload, [:glob] do |_task, args|
- QA::Tools::KnapsackReport.upload_report(args[:glob])
+ QA::Support::KnapsackReport.upload_report(args[:glob])
end
desc "Report long running spec files"
task :notify_long_running_specs do
- QA::Tools::LongRunningSpecReporter.execute
+ QA::Support::LongRunningSpecReporter.execute
end
end
-# rubocop:enable Rails/RakeEnvironment