diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-21 06:12:55 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-21 06:12:55 +0300 |
commit | b82d69110784e196facfbe3f8dfc8111393a5dac (patch) | |
tree | d0da7ee51cef64aa1256b16b19583d1f2b7624c5 /qa/spec/support/repeater_spec.rb | |
parent | 551734207fa6241cf444b1154294e9b82831ae9a (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'qa/spec/support/repeater_spec.rb')
-rw-r--r-- | qa/spec/support/repeater_spec.rb | 75 |
1 files changed, 54 insertions, 21 deletions
diff --git a/qa/spec/support/repeater_spec.rb b/qa/spec/support/repeater_spec.rb index da8d6b18fb0..8109c2cce7b 100644 --- a/qa/spec/support/repeater_spec.rb +++ b/qa/spec/support/repeater_spec.rb @@ -380,34 +380,67 @@ RSpec.describe QA::Support::Repeater do end end - it 'logs attempts' do - attempted = false - - expect do - subject.repeat_until(max_attempts: 1) do - unless attempted - attempted = true - break false - end + context 'with logging' do + before do + allow(QA::Runtime::Logger).to receive(:debug) + end + it 'skips logging single attempt with max_attempts' do + subject.repeat_until(max_attempts: 3) do true end - end.to output(/Attempt number/).to_stdout_from_any_process - end - it 'allows logging to be silenced' do - attempted = false - - expect do - subject.repeat_until(max_attempts: 1, log: false) do - unless attempted - attempted = true - break false - end + expect(QA::Runtime::Logger).not_to have_received(:debug) + end + it 'skips logging single attempt with max_duration' do + subject.repeat_until(max_duration: 3) do true end - end.not_to output.to_stdout_from_any_process + + expect(QA::Runtime::Logger).not_to have_received(:debug) + end + + it 'allows logging to be silenced' do + subject.repeat_until(max_attempts: 3, log: false, raise_on_failure: false) do + false + end + + expect(QA::Runtime::Logger).not_to have_received(:debug) + end + + it 'starts logging on subsequent attempts for max_duration' do + subject.repeat_until(max_duration: 0.3, sleep_interval: 0.1, raise_on_failure: false) do + false + end + + aggregate_failures do + expect(QA::Runtime::Logger).to have_received(:debug).with(<<~MSG.strip).ordered.once + Retrying action with: max_duration: 0.3; sleep_interval: 0.1; raise_on_failure: false; retry_on_exception: false + MSG + expect(QA::Runtime::Logger).to have_received(:debug).with('ended retry').ordered.once + expect(QA::Runtime::Logger).not_to have_received(:debug).with(/Attempt number/) + end + end + + it 'starts logging subsequent attempts for max_attempts' do + attempts = 0 + subject.repeat_until(max_attempts: 4, raise_on_failure: false) do + next true if attempts == 2 + + attempts += 1 + false + end + + aggregate_failures do + expect(QA::Runtime::Logger).to have_received(:debug).with(<<~MSG.strip).ordered.once + Retrying action with: max_attempts: 4; sleep_interval: 0; raise_on_failure: false; retry_on_exception: false + MSG + expect(QA::Runtime::Logger).to have_received(:debug).with('Attempt number 2').ordered.once + expect(QA::Runtime::Logger).to have_received(:debug).with('Attempt number 3').ordered.once + expect(QA::Runtime::Logger).to have_received(:debug).with('ended retry').ordered.once + end + end end end end |