Commit 9d52d643 authored by Andrejs Cunskis's avatar Andrejs Cunskis

Merge branch 'acunskis-rspec-retry-patch' into 'master'

E2E: Respect quarantine context for rspec-retry

See merge request gitlab-org/gitlab!78408
parents 53e05002 20c58a93
...@@ -174,7 +174,6 @@ module QA ...@@ -174,7 +174,6 @@ module QA
expect { imported_group.import_status }.to eventually_eq('finished').within(import_wait_duration) expect { imported_group.import_status }.to eventually_eq('finished').within(import_wait_duration)
imported_member = imported_group.reload!.members.find { |usr| usr.username == member.username } imported_member = imported_group.reload!.members.find { |usr| usr.username == member.username }
aggregate_failures do aggregate_failures do
expect(imported_member).not_to be_nil expect(imported_member).not_to be_nil
expect(imported_member.access_level).to eq(Resource::Members::AccessLevel::DEVELOPER) expect(imported_member.access_level).to eq(Resource::Members::AccessLevel::DEVELOPER)
......
...@@ -65,9 +65,9 @@ module QA ...@@ -65,9 +65,9 @@ module QA
'successfully imports repository', 'successfully imports repository',
testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/347570' testcase: 'https://gitlab.com/gitlab-org/gitlab/-/quality/test_cases/347570'
) do ) do
aggregate_failures do expect_import_finished
expect_import_finished
aggregate_failures do
expect(imported_commits).to match_array(source_commits) expect(imported_commits).to match_array(source_commits)
expect(imported_tags).to match_array(source_tags) expect(imported_tags).to match_array(source_tags)
expect(imported_branches).to match_array(source_branches) expect(imported_branches).to match_array(source_branches)
......
...@@ -11,9 +11,9 @@ module QA ...@@ -11,9 +11,9 @@ module QA
extend self extend self
# Skip tests in quarantine unless we explicitly focus on them. # Skip tests in quarantine unless we explicitly focus on them.
def skip_or_run_quarantined_tests_or_contexts(filters, example) def skip_or_run_quarantined_tests_or_contexts(example)
if filters.key?(:quarantine) if filters.key?(:quarantine)
included_filters = filters_other_than_quarantine(filters) included_filters = filters_other_than_quarantine
# If :quarantine is focused, skip the test/context unless its metadata # If :quarantine is focused, skip the test/context unless its metadata
# includes quarantine and any other filters # includes quarantine and any other filters
...@@ -29,18 +29,17 @@ module QA ...@@ -29,18 +29,17 @@ module QA
elsif example.metadata.key?(:quarantine) elsif example.metadata.key?(:quarantine)
quarantine_tag = example.metadata[:quarantine] quarantine_tag = example.metadata[:quarantine]
if quarantine_tag.is_a?(Hash) && quarantine_tag&.key?(:only) && !ContextSelector.context_matches?(quarantine_tag[:only]) # If the :quarantine hash contains :only, we respect that.
# If the :quarantine hash contains :only, we respect that. # For instance `quarantine: { only: { subdomain: :staging } }`
# For instance `quarantine: { only: { subdomain: :staging } }` will only quarantine the test when it runs against staging. # will only quarantine the test when it runs against staging.
return return if quarantined_different_context?(quarantine_tag)
end
example.metadata[:skip] = quarantine_message(quarantine_tag) example.metadata[:skip] = quarantine_message(quarantine_tag)
end end
end end
def filters_other_than_quarantine(filter) def filters_other_than_quarantine
filter.reject { |key, _| key == :quarantine } filters.reject { |key, _| key == :quarantine }
end end
def quarantine_message(quarantine_tag) def quarantine_message(quarantine_tag)
...@@ -70,6 +69,14 @@ module QA ...@@ -70,6 +69,14 @@ module QA
(metadata.keys & included_filters.keys).empty? (metadata.keys & included_filters.keys).empty?
end end
def quarantined_different_context?(quarantine)
quarantine.is_a?(Hash) && quarantine.key?(:only) && !ContextSelector.context_matches?(quarantine[:only])
end
def filters
@filters ||= ::RSpec.configuration.inclusion_filter.rules
end
end end
end end
end end
......
...@@ -18,7 +18,7 @@ module QA ...@@ -18,7 +18,7 @@ module QA
def example_group_started(example_group_notification) def example_group_started(example_group_notification)
group = example_group_notification.group group = example_group_notification.group
skip_or_run_quarantined_tests_or_contexts(filters, group) skip_or_run_quarantined_tests_or_contexts(group)
end end
# Starts example # Starts example
...@@ -28,13 +28,7 @@ module QA ...@@ -28,13 +28,7 @@ module QA
example = example_notification.example example = example_notification.example
# if skip propagated from example_group, do not reset skip metadata # if skip propagated from example_group, do not reset skip metadata
skip_or_run_quarantined_tests_or_contexts(filters, example) unless example.metadata[:skip] skip_or_run_quarantined_tests_or_contexts(example) unless example.metadata[:skip]
end
private
def filters
@filters ||= ::RSpec.configuration.inclusion_filter.rules
end end
end end
end end
......
...@@ -100,8 +100,14 @@ RSpec.configure do |config| ...@@ -100,8 +100,14 @@ RSpec.configure do |config|
if ENV['CI'] && !QA::Runtime::Env.disable_rspec_retry? if ENV['CI'] && !QA::Runtime::Env.disable_rspec_retry?
non_quarantine_retries = QA::Runtime::Env.ci_project_name =~ /staging|canary|production/ ? 3 : 2 non_quarantine_retries = QA::Runtime::Env.ci_project_name =~ /staging|canary|production/ ? 3 : 2
config.around do |example| config.around do |example|
retry_times = example.metadata.key?(:quarantine) ? 1 : non_quarantine_retries quarantine = example.metadata[:quarantine]
example.run_with_retry retry: retry_times 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 end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment