summaryrefslogtreecommitdiff
path: root/qa/spec
diff options
context:
space:
mode:
authorGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 09:08:42 +0000
committerGitLab Bot <gitlab-bot@gitlab.com>2021-08-19 09:08:42 +0000
commitb76ae638462ab0f673e5915986070518dd3f9ad3 (patch)
treebdab0533383b52873be0ec0eb4d3c66598ff8b91 /qa/spec
parent434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff)
downloadgitlab-ce-b76ae638462ab0f673e5915986070518dd3f9ad3.tar.gz
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'qa/spec')
-rw-r--r--qa/spec/page/logging_spec.rb1
-rw-r--r--qa/spec/qa_deprecation_toolkit_env.rb22
-rw-r--r--qa/spec/resource/base_spec.rb78
-rw-r--r--qa/spec/runtime/api/request_spec.rb2
-rw-r--r--qa/spec/spec_helper.rb7
-rw-r--r--qa/spec/specs/allure_report_spec.rb93
-rw-r--r--qa/spec/specs/helpers/context_selector_spec.rb28
-rw-r--r--qa/spec/specs/helpers/quarantine_spec.rb28
-rw-r--r--qa/spec/support/allure_metadata_formatter_spec.rb46
-rw-r--r--qa/spec/support/matchers/eventually_matcher.rb19
-rw-r--r--qa/spec/support/retrier_spec.rb10
11 files changed, 242 insertions, 92 deletions
diff --git a/qa/spec/page/logging_spec.rb b/qa/spec/page/logging_spec.rb
index df3447770be..3e1011dcd2a 100644
--- a/qa/spec/page/logging_spec.rb
+++ b/qa/spec/page/logging_spec.rb
@@ -12,6 +12,7 @@ RSpec.describe QA::Support::Page::Logging do
QA::Runtime::Logger.logger = logger
allow(Capybara).to receive(:current_session).and_return(page)
+ allow(page).to receive(:find).and_return(page)
allow(page).to receive(:current_url).and_return('http://current-url')
allow(page).to receive(:has_css?).with(any_args).and_return(true)
end
diff --git a/qa/spec/qa_deprecation_toolkit_env.rb b/qa/spec/qa_deprecation_toolkit_env.rb
new file mode 100644
index 00000000000..cdd5d954b20
--- /dev/null
+++ b/qa/spec/qa_deprecation_toolkit_env.rb
@@ -0,0 +1,22 @@
+# frozen_string_literal: true
+
+require 'deprecation_toolkit'
+require 'deprecation_toolkit/rspec'
+require 'concurrent/utility/monotonic_time'
+require 'active_support/gem_version'
+
+module QaDeprecationToolkitEnv
+ # Taken from https://github.com/jeremyevans/ruby-warning/blob/1.1.0/lib/warning.rb#L18
+ 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
+
+ def self.configure!
+ # Enable ruby deprecations for keywords, it's suppressed by default in Ruby 2.7.2
+ Warning[:deprecated] = true
+
+ DeprecationToolkit::Configuration.test_runner = :rspec
+ DeprecationToolkit::Configuration.deprecation_path = 'deprecations'
+ DeprecationToolkit::Configuration.warnings_treated_as_deprecation = [kwargs_warning]
+ end
+end
diff --git a/qa/spec/resource/base_spec.rb b/qa/spec/resource/base_spec.rb
index c0bedf794be..c6dd56b5f47 100644
--- a/qa/spec/resource/base_spec.rb
+++ b/qa/spec/resource/base_spec.rb
@@ -6,7 +6,7 @@ RSpec.describe QA::Resource::Base do
let(:resource) { spy('resource') }
let(:location) { 'http://location' }
- shared_context 'fabrication context' do
+ shared_context 'with fabrication context' do
subject do
Class.new(described_class) do
def self.name
@@ -28,24 +28,14 @@ RSpec.describe QA::Resource::Base do
expect(resource).to receive(:something!).ordered
expect(resource).to receive(fabrication_method_used).ordered.and_return(location)
- subject.public_send(fabrication_method_called, resource: resource) do |resource|
- resource.something!
- end
- end
-
- it 'does not log the resource and build method when QA_DEBUG=false' do
- stub_env('QA_DEBUG', 'false')
- expect(resource).to receive(fabrication_method_used).and_return(location)
-
- expect { subject.public_send(fabrication_method_called, 'something', resource: resource) }
- .not_to output.to_stdout
+ subject.public_send(fabrication_method_called, resource: resource, &:something!)
end
end
describe '.fabricate!' do
context 'when resource does not support fabrication via the API' do
before do
- expect(described_class).to receive(:fabricate_via_api!).and_raise(NotImplementedError)
+ allow(described_class).to receive(:fabricate_via_api!).and_raise(NotImplementedError)
end
it 'calls .fabricate_via_browser_ui!' do
@@ -65,7 +55,7 @@ RSpec.describe QA::Resource::Base do
end
describe '.fabricate_via_api!' do
- include_context 'fabrication context'
+ include_context 'with fabrication context'
it_behaves_like 'fabrication method', :fabricate_via_api!
@@ -77,18 +67,25 @@ RSpec.describe QA::Resource::Base do
expect(result).to eq(resource)
end
- it 'logs the resource and build method when QA_DEBUG=true' do
- stub_env('QA_DEBUG', 'true')
- expect(resource).to receive(:fabricate_via_api!).and_return(location)
+ context "with debug log level" do
+ before do
+ allow(QA::Runtime::Logger).to receive(:debug)
+ end
+
+ it 'logs the resource and build method' do
+ stub_env('QA_DEBUG', 'true')
+
+ subject.fabricate_via_api!('something', resource: resource, parents: [])
- expect { subject.fabricate_via_api!('something', resource: resource, parents: []) }
- .to output(/==> Built a MyResource via api in [\d\.\-e]+ seconds+/)
- .to_stdout
+ expect(QA::Runtime::Logger).to have_received(:debug) do |&msg|
+ expect(msg.call).to match_regex(/==> Built a MyResource via api in [\d.\-e]+ seconds+/)
+ end
+ end
end
end
describe '.fabricate_via_browser_ui!' do
- include_context 'fabrication context'
+ include_context 'with fabrication context'
it_behaves_like 'fabrication method', :fabricate_via_browser_ui!, :fabricate!
@@ -104,16 +101,24 @@ RSpec.describe QA::Resource::Base do
expect(result).to eq(resource)
end
- it 'logs the resource and build method when QA_DEBUG=true' do
- stub_env('QA_DEBUG', 'true')
+ context "with debug log level" do
+ before do
+ allow(QA::Runtime::Logger).to receive(:debug)
+ end
+
+ it 'logs the resource and build method' do
+ stub_env('QA_DEBUG', 'true')
+
+ subject.fabricate_via_browser_ui!('something', resource: resource, parents: [])
- expect { subject.fabricate_via_browser_ui!('something', resource: resource, parents: []) }
- .to output(/==> Built a MyResource via browser_ui in [\d\.\-e]+ seconds+/)
- .to_stdout
+ expect(QA::Runtime::Logger).to have_received(:debug) do |&msg|
+ expect(msg.call).to match_regex(/==> Built a MyResource via browser_ui in [\d.\-e]+ seconds+/)
+ end
+ end
end
end
- shared_context 'simple resource' do
+ shared_context 'with simple resource' do
subject do
Class.new(QA::Resource::Base) do
attribute :test do
@@ -136,7 +141,7 @@ RSpec.describe QA::Resource::Base do
end
describe '.attribute' do
- include_context 'simple resource'
+ include_context 'with simple resource'
context 'when the attribute is populated via a block' do
it 'returns value from the block' do
@@ -151,7 +156,7 @@ RSpec.describe QA::Resource::Base do
let(:api_resource) { { no_block: 'api' } }
before do
- expect(resource).to receive(:api_resource).and_return(api_resource)
+ allow(resource).to receive(:api_resource).and_return(api_resource)
end
it 'returns value from api' do
@@ -165,16 +170,16 @@ RSpec.describe QA::Resource::Base do
let(:api_resource) { { test: 'api_with_block' } }
before do
- allow(QA::Runtime::Logger).to receive(:info)
+ allow(QA::Runtime::Logger).to receive(:debug)
end
- it 'returns value from api and emits an INFO log entry' do
+ it 'returns value from api and emits an debug log entry' do
result = subject.fabricate!(resource: resource)
expect(result).to be_a(described_class)
expect(result.test).to eq('api_with_block')
expect(QA::Runtime::Logger)
- .to have_received(:info).with(/api_with_block/)
+ .to have_received(:debug).with(/api_with_block/)
end
end
end
@@ -209,8 +214,9 @@ RSpec.describe QA::Resource::Base do
it 'raises an error because no values could be found' do
result = subject.fabricate!(resource: resource)
- expect { result.no_block }
- .to raise_error(described_class::NoValueError, "No value was computed for no_block of #{resource.class.name}.")
+ expect { result.no_block }.to raise_error(
+ described_class::NoValueError, "No value was computed for no_block of #{resource.class.name}."
+ )
end
end
@@ -254,7 +260,7 @@ RSpec.describe QA::Resource::Base do
end
describe '#web_url' do
- include_context 'simple resource'
+ include_context 'with simple resource'
it 'sets #web_url to #current_url after fabrication' do
subject.fabricate!(resource: resource)
@@ -264,7 +270,7 @@ RSpec.describe QA::Resource::Base do
end
describe '#visit!' do
- include_context 'simple resource'
+ include_context 'with simple resource'
before do
allow(resource).to receive(:visit)
diff --git a/qa/spec/runtime/api/request_spec.rb b/qa/spec/runtime/api/request_spec.rb
index 93de2f4a87e..a1de71d31f0 100644
--- a/qa/spec/runtime/api/request_spec.rb
+++ b/qa/spec/runtime/api/request_spec.rb
@@ -14,7 +14,7 @@ RSpec.describe QA::Runtime::API::Request do
end
context 'when oauth_access_token is passed in the query string' do
- let(:request) { described_class.new(client, '/users', { oauth_access_token: 'foo' }) }
+ let(:request) { described_class.new(client, '/users', oauth_access_token: 'foo') }
it 'does not adds a private_token query string' do
expect(request.url).to eq 'http://example.com/api/v4/users?oauth_access_token=foo'
diff --git a/qa/spec/spec_helper.rb b/qa/spec/spec_helper.rb
index f4bfd57504e..0df7b94b894 100644
--- a/qa/spec/spec_helper.rb
+++ b/qa/spec/spec_helper.rb
@@ -6,6 +6,9 @@ require 'rspec-parameterized'
require 'active_support/core_ext/hash'
require 'active_support/core_ext/object/blank'
+require_relative 'qa_deprecation_toolkit_env'
+QaDeprecationToolkitEnv.configure!
+
if ENV['CI'] && QA::Runtime::Env.knapsack? && !ENV['NO_KNAPSACK']
require 'knapsack'
Knapsack::Adapters::RSpecAdapter.bind
@@ -23,8 +26,8 @@ Dir[::File.join(__dir__, "support/shared_examples/*.rb")].sort.each { |f| requir
RSpec.configure do |config|
config.include ::Matchers
- QA::Specs::Helpers::Quarantine.configure_rspec
- QA::Specs::Helpers::ContextSelector.configure_rspec
+ config.add_formatter QA::Specs::Helpers::ContextFormatter
+ config.add_formatter QA::Specs::Helpers::QuarantineFormatter
config.before do |example|
QA::Runtime::Logger.debug("\nStarting test: #{example.full_description}\n")
diff --git a/qa/spec/specs/allure_report_spec.rb b/qa/spec/specs/allure_report_spec.rb
new file mode 100644
index 00000000000..27bc0dd3d1d
--- /dev/null
+++ b/qa/spec/specs/allure_report_spec.rb
@@ -0,0 +1,93 @@
+# frozen_string_literal: true
+
+require 'allure-rspec'
+
+describe QA::Runtime::AllureReport do
+ include Helpers::StubENV
+
+ let(:rspec_config) { double('RSpec::Core::Configuration', 'add_formatter': nil, after: nil) }
+
+ let(:png_path) { 'png_path' }
+ let(:html_path) { 'html_path' }
+
+ let(:allure_config) do
+ # need to mock config in case the test itself is executed with allure reporting enabled
+ AllureRspec::RspecConfig.send(:new).tap do |conf|
+ conf.instance_variable_set(:@allure_config, Allure::Config.send(:new))
+ end
+ end
+
+ before do
+ stub_env('QA_GENERATE_ALLURE_REPORT', generate_report)
+
+ allow(AllureRspec).to receive(:configure).and_yield(allure_config)
+ allow(RSpec).to receive(:configure).and_yield(rspec_config)
+ allow(Capybara::Screenshot).to receive(:after_save_screenshot).and_yield(png_path)
+ allow(Capybara::Screenshot).to receive(:after_save_html).and_yield(html_path)
+ end
+
+ context 'with report generation disabled' do
+ let(:generate_report) { 'false' }
+
+ it 'does not perform configuration' do
+ aggregate_failures do
+ expect(described_class.configure!).to be_nil
+
+ expect(AllureRspec).not_to have_received(:configure)
+ expect(RSpec).not_to have_received(:configure)
+ expect(Capybara::Screenshot).not_to have_received(:after_save_screenshot)
+ expect(Capybara::Screenshot).not_to have_received(:after_save_html)
+ end
+ end
+ end
+
+ context 'with report generation enabled' do
+ let(:generate_report) { 'true' }
+
+ let(:png_file) { 'png-file' }
+ let(:html_file) { 'html-file' }
+ let(:ci_job) { 'ee:relative 5' }
+
+ before do
+ stub_env('CI', 'true')
+ stub_env('CI_JOB_NAME', ci_job)
+
+ allow(Allure).to receive(:add_attachment)
+ allow(File).to receive(:open).with(png_path) { png_file }
+ allow(File).to receive(:open).with(html_path) { html_file }
+
+ described_class.configure!
+ end
+
+ it 'configures Allure options' do
+ aggregate_failures do
+ expect(allure_config.results_directory).to eq('tmp/allure-results')
+ expect(allure_config.clean_results_directory).to eq(true)
+ expect(allure_config.environment_properties).to be_a_kind_of(Hash)
+ expect(allure_config.environment).to eq('ee:relative')
+ end
+ end
+
+ it 'adds rspec and metadata formatter' do
+ expect(rspec_config).to have_received(:add_formatter).with(AllureRspecFormatter).ordered
+ expect(rspec_config).to have_received(:add_formatter).with(QA::Support::AllureMetadataFormatter).ordered
+ end
+
+ it 'configures screenshot saving' do
+ aggregate_failures do
+ expect(Allure).to have_received(:add_attachment).with(
+ name: 'screenshot',
+ source: png_file,
+ type: Allure::ContentType::PNG,
+ test_case: true
+ )
+ expect(Allure).to have_received(:add_attachment).with(
+ name: 'html',
+ source: html_file,
+ type: 'text/html',
+ test_case: true
+ )
+ end
+ end
+ end
+end
diff --git a/qa/spec/specs/helpers/context_selector_spec.rb b/qa/spec/specs/helpers/context_selector_spec.rb
index f0250103008..cbdbe6698ae 100644
--- a/qa/spec/specs/helpers/context_selector_spec.rb
+++ b/qa/spec/specs/helpers/context_selector_spec.rb
@@ -2,29 +2,25 @@
require 'rspec/core/sandbox'
-RSpec.configure do |c|
- c.around do |ex|
+RSpec.describe QA::Specs::Helpers::ContextSelector do
+ include Helpers::StubENV
+ include QA::Specs::Helpers::RSpec
+
+ around do |ex|
+ QA::Runtime::Scenario.define(:gitlab_address, 'https://staging.gitlab.com')
+
RSpec::Core::Sandbox.sandboxed do |config|
+ config.formatter = QA::Specs::Helpers::ContextFormatter
+
# If there is an example-within-an-example, we want to make sure the inner example
# does not get a reference to the outer example (the real spec) if it calls
# something like `pending`
config.before(:context) { RSpec.current_example = nil }
-
config.color_mode = :off
ex.run
end
end
-end
-
-RSpec.describe QA::Specs::Helpers::ContextSelector do
- include Helpers::StubENV
- include QA::Specs::Helpers::RSpec
-
- before do
- QA::Runtime::Scenario.define(:gitlab_address, 'https://staging.gitlab.com')
- described_class.configure_rspec
- end
describe '.context_matches?' do
it 'returns true when url has .com' do
@@ -104,7 +100,6 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do
context 'with different environment set' do
before do
QA::Runtime::Scenario.define(:gitlab_address, 'https://gitlab.com')
- described_class.configure_rspec
end
it 'does not run against production' do
@@ -239,7 +234,6 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do
context 'without CI_PROJECT_NAME set' do
before do
stub_env('CI_PROJECT_NAME', nil)
- described_class.configure_rspec
end
it 'runs on any pipeline' do
@@ -273,7 +267,6 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do
context 'when a pipeline triggered from the default branch runs in gitlab-qa' do
before do
stub_env('CI_PROJECT_NAME', 'gitlab-qa')
- described_class.configure_rspec
end
it 'runs on default branch pipelines' do
@@ -310,7 +303,6 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do
context 'with CI_PROJECT_NAME set' do
before do
stub_env('CI_PROJECT_NAME', 'NIGHTLY')
- described_class.configure_rspec
end
it 'runs on designated pipeline' do
@@ -353,7 +345,6 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do
context 'without CI_JOB_NAME set' do
before do
stub_env('CI_JOB_NAME', nil)
- described_class.configure_rspec
end
context 'when excluding contexts' do
@@ -396,7 +387,6 @@ RSpec.describe QA::Specs::Helpers::ContextSelector do
context 'with CI_JOB_NAME set' do
before do
stub_env('CI_JOB_NAME', 'ee:instance-image')
- described_class.configure_rspec
end
context 'when excluding contexts' do
diff --git a/qa/spec/specs/helpers/quarantine_spec.rb b/qa/spec/specs/helpers/quarantine_spec.rb
index 45754a09b17..548a8510988 100644
--- a/qa/spec/specs/helpers/quarantine_spec.rb
+++ b/qa/spec/specs/helpers/quarantine_spec.rb
@@ -2,9 +2,14 @@
require 'rspec/core/sandbox'
-RSpec.configure do |c|
- c.around do |ex|
+RSpec.describe QA::Specs::Helpers::Quarantine do
+ include Helpers::StubENV
+ include QA::Specs::Helpers::RSpec
+
+ around do |ex|
RSpec::Core::Sandbox.sandboxed do |config|
+ config.formatter = QA::Specs::Helpers::QuarantineFormatter
+
# If there is an example-within-an-example, we want to make sure the inner example
# does not get a reference to the outer example (the real spec) if it calls
# something like `pending`
@@ -15,18 +20,9 @@ RSpec.configure do |c|
ex.run
end
end
-end
-
-RSpec.describe QA::Specs::Helpers::Quarantine do
- include Helpers::StubENV
- include QA::Specs::Helpers::RSpec
describe '.skip_or_run_quarantined_contexts' do
context 'with no tag focused' do
- before do
- described_class.configure_rspec
- end
-
it 'skips before hooks of quarantined contexts' do
executed_hooks = []
@@ -66,7 +62,6 @@ RSpec.describe QA::Specs::Helpers::Quarantine do
context 'with :quarantine focused' do
before do
- described_class.configure_rspec
RSpec.configure do |c|
c.filter_run :quarantine
end
@@ -110,10 +105,6 @@ RSpec.describe QA::Specs::Helpers::Quarantine do
describe '.skip_or_run_quarantined_tests_or_contexts' do
context 'with no tag focused' do
- before do
- described_class.configure_rspec
- end
-
it 'skips quarantined tests' do
group = describe_successfully do
it('is pending', :quarantine) {}
@@ -135,7 +126,6 @@ RSpec.describe QA::Specs::Helpers::Quarantine do
context 'with environment set' do
before do
QA::Runtime::Scenario.define(:gitlab_address, 'https://staging.gitlab.com')
- described_class.configure_rspec
end
context 'no pipeline specified' do
@@ -168,7 +158,6 @@ RSpec.describe QA::Specs::Helpers::Quarantine do
shared_examples 'skipped in project' do |project|
before do
stub_env('CI_PROJECT_NAME', project)
- described_class.configure_rspec
end
it "is skipped in #{project}" do
@@ -209,7 +198,6 @@ RSpec.describe QA::Specs::Helpers::Quarantine do
context 'with :quarantine focused' do
before do
- described_class.configure_rspec
RSpec.configure do |c|
c.filter_run :quarantine
end
@@ -234,7 +222,6 @@ RSpec.describe QA::Specs::Helpers::Quarantine do
context 'with a non-quarantine tag focused' do
before do
- described_class.configure_rspec
RSpec.configure do |c|
c.filter_run :foo
end
@@ -277,7 +264,6 @@ RSpec.describe QA::Specs::Helpers::Quarantine do
context 'with :quarantine and non-quarantine tags focused' do
before do
- described_class.configure_rspec
RSpec.configure do |c|
c.filter_run :foo, :bar, :quarantine
end
diff --git a/qa/spec/support/allure_metadata_formatter_spec.rb b/qa/spec/support/allure_metadata_formatter_spec.rb
new file mode 100644
index 00000000000..cb208642716
--- /dev/null
+++ b/qa/spec/support/allure_metadata_formatter_spec.rb
@@ -0,0 +1,46 @@
+# frozen_string_literal: true
+
+describe QA::Support::AllureMetadataFormatter do
+ include Helpers::StubENV
+
+ let(:formatter) { described_class.new(StringIO.new) }
+
+ let(:rspec_example_notification) { double('RSpec::Core::Notifications::ExampleNotification', example: rspec_example) }
+ let(:rspec_example) do
+ double(
+ 'RSpec::Core::Example',
+ tms: nil,
+ issue: nil,
+ add_link: nil,
+ attempts: 0,
+ file_path: 'file/path/spec.rb',
+ metadata: {
+ testcase: 'testcase',
+ quarantine: { issue: 'issue' }
+ }
+ )
+ end
+
+ let(:ci_job) { 'ee:relative 5' }
+ let(:ci_job_url) { 'url' }
+
+ before do
+ stub_env('CI', 'true')
+ stub_env('CI_JOB_NAME', ci_job)
+ stub_env('CI_JOB_URL', ci_job_url)
+ end
+
+ it "adds additional data to report" do
+ formatter.example_started(rspec_example_notification)
+
+ aggregate_failures do
+ expect(rspec_example).to have_received(:tms).with('Testcase', 'testcase')
+ expect(rspec_example).to have_received(:issue).with('Quarantine issue', 'issue')
+ expect(rspec_example).to have_received(:add_link).with(name: "Job(#{ci_job})", url: ci_job_url)
+ expect(rspec_example).to have_received(:issue).with(
+ 'Failure issues',
+ 'https://gitlab.com/gitlab-org/gitlab/-/issues?scope=all&state=opened&search=spec.rb'
+ )
+ end
+ end
+end
diff --git a/qa/spec/support/matchers/eventually_matcher.rb b/qa/spec/support/matchers/eventually_matcher.rb
index 3f0afd6fb54..7a35a3165ae 100644
--- a/qa/spec/support/matchers/eventually_matcher.rb
+++ b/qa/spec/support/matchers/eventually_matcher.rb
@@ -9,7 +9,7 @@
# expect { Something.that.takes.time.to_appear }.not_to eventually_eq(expected_result)
#
# With duration and attempts override
-# expect { Something.that.takes.time.to_appear }.to eventually_eq(expected_result).within(duration: 10, attempts: 5)
+# expect { Something.that.takes.time.to_appear }.to eventually_eq(expected_result).within(max_duration: 10, max_attempts: 5)
module Matchers
%w[
@@ -21,9 +21,9 @@ module Matchers
be_empty
].each do |op|
RSpec::Matchers.define(:"eventually_#{op}") do |*expected|
- chain(:within) do |options = {}|
- @duration = options[:duration]
- @attempts = options[:attempts]
+ chain(:within) do |kwargs = {}|
+ @retry_args = kwargs
+ @retry_args[:sleep_interval] = 0.5 unless @retry_args[:sleep_interval]
end
def supports_block_expectations?
@@ -52,11 +52,12 @@ module Matchers
# @param [Symbol] expectation_name
# @return [Boolean]
def wait_and_check(actual, expectation_name)
- QA::Support::Retrier.retry_until(
- max_attempts: @attempts,
- max_duration: @duration,
- sleep_interval: 0.5
- ) do
+ attempt = 0
+
+ QA::Runtime::Logger.debug("Running eventually matcher with '#{operator_msg}' operator")
+ QA::Support::Retrier.retry_until(**@retry_args) do
+ QA::Runtime::Logger.debug("evaluating expectation, attempt: #{attempt += 1}")
+
public_send(expectation_name, actual)
rescue RSpec::Expectations::ExpectationNotMetError, QA::Resource::ApiFabricator::ResourceNotFoundError
false
diff --git a/qa/spec/support/retrier_spec.rb b/qa/spec/support/retrier_spec.rb
index 6f052519516..4e27915553c 100644
--- a/qa/spec/support/retrier_spec.rb
+++ b/qa/spec/support/retrier_spec.rb
@@ -70,8 +70,9 @@ RSpec.describe QA::Support::Retrier do
describe '.retry_on_exception' do
context 'when the condition is true' do
it 'logs max_attempts, reload_page, and sleep_interval parameters' do
- expect { subject.retry_on_exception(max_attempts: 1, reload_page: nil, sleep_interval: 0) { true } }
- .to output(/with retry_on_exception: max_attempts: 1; reload_page: ; sleep_interval: 0/).to_stdout_from_any_process
+ message = /with retry_on_exception: max_attempts: 1; reload_page: true; sleep_interval: 0/
+ expect { subject.retry_on_exception(max_attempts: 1, reload_page: true, sleep_interval: 0) { true } }
+ .to output(message).to_stdout_from_any_process
end
it 'logs the end' do
@@ -82,8 +83,9 @@ RSpec.describe QA::Support::Retrier do
context 'when the condition is false' do
it 'logs the start' do
- expect { subject.retry_on_exception(max_attempts: 1, reload_page: nil, sleep_interval: 0) { false } }
- .to output(/with retry_on_exception: max_attempts: 1; reload_page: ; sleep_interval: 0/).to_stdout_from_any_process
+ message = /with retry_on_exception: max_attempts: 1; reload_page: true; sleep_interval: 0/
+ expect { subject.retry_on_exception(max_attempts: 1, reload_page: true, sleep_interval: 0) { false } }
+ .to output(message).to_stdout_from_any_process
end
it 'logs the end' do