diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-11-18 16:16:36 +0300 |
commit | 311b0269b4eb9839fa63f80c8d7a58f32b8138a0 (patch) | |
tree | 07e7870bca8aed6d61fdcc810731c50d2c40af47 /qa/spec/support/repeater_spec.rb | |
parent | 27909cef6c4170ed9205afa7426b8d3de47cbb0c (diff) |
Add latest changes from gitlab-org/gitlab@14-5-stable-eev14.5.0-rc42
Diffstat (limited to 'qa/spec/support/repeater_spec.rb')
-rw-r--r-- | qa/spec/support/repeater_spec.rb | 114 |
1 files changed, 86 insertions, 28 deletions
diff --git a/qa/spec/support/repeater_spec.rb b/qa/spec/support/repeater_spec.rb index da8d6b18fb0..4fa3bcde5e7 100644 --- a/qa/spec/support/repeater_spec.rb +++ b/qa/spec/support/repeater_spec.rb @@ -23,7 +23,7 @@ RSpec.describe QA::Support::Repeater do context 'when retry_on_exception is not provided (default: false)' do context 'when max_duration is provided' do context 'when max duration is reached' do - it 'raises an exception' do + it 'raises an exception with default message' do expect do Timecop.freeze do subject.repeat_until(max_duration: 1) do @@ -31,7 +31,20 @@ RSpec.describe QA::Support::Repeater do false end end - end.to raise_error(QA::Support::Repeater::WaitExceededError, "Wait condition not met after 1 second") + end.to raise_error(QA::Support::Repeater::WaitExceededError, "Wait failed after 1 second") + end + + it 'raises an exception with custom message' do + message = 'Some custom action' + + expect do + Timecop.freeze do + subject.repeat_until(max_duration: 1, message: message) do + Timecop.travel(2) + false + end + end + end.to raise_error(QA::Support::Repeater::WaitExceededError, "#{message} failed after 1 second") end it 'ignores attempts' do @@ -70,14 +83,26 @@ RSpec.describe QA::Support::Repeater do context 'when max_attempts is provided' do context 'when max_attempts is reached' do - it 'raises an exception' do + it 'raises an exception with default message' do expect do Timecop.freeze do subject.repeat_until(max_attempts: 1) do false end end - end.to raise_error(QA::Support::Repeater::RetriesExceededError, "Retry condition not met after 1 attempt") + end.to raise_error(QA::Support::Repeater::RetriesExceededError, "Retry failed after 1 attempt") + end + + it 'raises an exception with custom message' do + message = 'Some custom action' + + expect do + Timecop.freeze do + subject.repeat_until(max_attempts: 1, message: message) do + false + end + end + end.to raise_error(QA::Support::Repeater::RetriesExceededError, "#{message} failed after 1 attempt") end it 'ignores duration' do @@ -126,7 +151,7 @@ RSpec.describe QA::Support::Repeater do false end end - end.to raise_error(QA::Support::Repeater::RetriesExceededError, "Retry condition not met after 1 attempt") + end.to raise_error(QA::Support::Repeater::RetriesExceededError, "Retry failed after 1 attempt") end end @@ -141,7 +166,7 @@ RSpec.describe QA::Support::Repeater do false end end - end.to raise_error(QA::Support::Repeater::WaitExceededError, "Wait condition not met after 1 second") + end.to raise_error(QA::Support::Repeater::WaitExceededError, "Wait failed after 1 second") end end end @@ -210,7 +235,7 @@ RSpec.describe QA::Support::Repeater do false end end - end.to raise_error(QA::Support::Repeater::RetriesExceededError, "Retry condition not met after 1 attempt") + end.to raise_error(QA::Support::Repeater::RetriesExceededError, "Retry failed after 1 attempt") end end @@ -225,7 +250,7 @@ RSpec.describe QA::Support::Repeater do false end end - end.to raise_error(QA::Support::Repeater::WaitExceededError, "Wait condition not met after 1 second") + end.to raise_error(QA::Support::Repeater::WaitExceededError, "Wait failed after 1 second") end end end @@ -380,34 +405,67 @@ RSpec.describe QA::Support::Repeater do end end - it 'logs attempts' do - attempted = false + context 'with logging' do + before do + allow(QA::Runtime::Logger).to receive(:debug) + end - expect do - subject.repeat_until(max_attempts: 1) do - unless attempted - attempted = true - break false - end + it 'skips logging single attempt with max_attempts' do + subject.repeat_until(max_attempts: 3) do + true + 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.to output(/Attempt number/).to_stdout_from_any_process - end - it 'allows logging to be silenced' do - attempted = false + expect(QA::Runtime::Logger).not_to have_received(:debug) + end - expect do - subject.repeat_until(max_attempts: 1, log: false) do - unless attempted - attempted = true - break false - end + it 'allows logging to be silenced' do + subject.repeat_until(max_attempts: 3, log: false, raise_on_failure: false) do + false + end - true + 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 - end.not_to output.to_stdout_from_any_process + + 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 |