Commit 50d3b8b7 authored by Sanad Liaquat's avatar Sanad Liaquat

Merge branch 'ml-do-not-log-wait-for-requests-wait-until' into 'master'

Don't log `wait_for_requests` use of `wait_until`

See merge request gitlab-org/gitlab!25215
parents 3dae6040 5540358a
...@@ -10,13 +10,13 @@ module QA ...@@ -10,13 +10,13 @@ module QA
RetriesExceededError = Class.new(RuntimeError) RetriesExceededError = Class.new(RuntimeError)
WaitExceededError = Class.new(RuntimeError) WaitExceededError = Class.new(RuntimeError)
def repeat_until(max_attempts: nil, max_duration: nil, reload_page: nil, sleep_interval: 0, raise_on_failure: true, retry_on_exception: false) def repeat_until(max_attempts: nil, max_duration: nil, reload_page: nil, sleep_interval: 0, raise_on_failure: true, retry_on_exception: false, log: true)
attempts = 0 attempts = 0
start = Time.now start = Time.now
begin begin
while remaining_attempts?(attempts, max_attempts) && remaining_time?(start, max_duration) while remaining_attempts?(attempts, max_attempts) && remaining_time?(start, max_duration)
QA::Runtime::Logger.debug("Attempt number #{attempts + 1}") if max_attempts QA::Runtime::Logger.debug("Attempt number #{attempts + 1}") if max_attempts && log
result = yield result = yield
return result if result return result if result
......
...@@ -6,7 +6,7 @@ module QA ...@@ -6,7 +6,7 @@ module QA
module_function module_function
def wait_for_requests def wait_for_requests
Waiter.wait_until do Waiter.wait_until(log: false) do
finished_all_ajax_requests? && finished_all_axios_requests? finished_all_ajax_requests? && finished_all_axios_requests?
end end
end end
......
...@@ -7,15 +7,17 @@ module QA ...@@ -7,15 +7,17 @@ module QA
module_function module_function
def wait_until(max_duration: singleton_class::DEFAULT_MAX_WAIT_TIME, reload_page: nil, sleep_interval: 0.1, raise_on_failure: true, retry_on_exception: false) def wait_until(max_duration: singleton_class::DEFAULT_MAX_WAIT_TIME, reload_page: nil, sleep_interval: 0.1, raise_on_failure: true, retry_on_exception: false, log: true)
QA::Runtime::Logger.debug( if log
<<~MSG.tr("\n", ' ') QA::Runtime::Logger.debug(
with wait_until: max_duration: #{max_duration}; <<~MSG.tr("\n", ' ')
reload_page: #{reload_page}; with wait_until: max_duration: #{max_duration};
sleep_interval: #{sleep_interval}; reload_page: #{reload_page};
raise_on_failure: #{raise_on_failure} sleep_interval: #{sleep_interval};
MSG raise_on_failure: #{raise_on_failure}
) MSG
)
end
result = nil result = nil
self.repeat_until( self.repeat_until(
...@@ -23,11 +25,12 @@ module QA ...@@ -23,11 +25,12 @@ module QA
reload_page: reload_page, reload_page: reload_page,
sleep_interval: sleep_interval, sleep_interval: sleep_interval,
raise_on_failure: raise_on_failure, raise_on_failure: raise_on_failure,
retry_on_exception: retry_on_exception retry_on_exception: retry_on_exception,
log: log
) do ) do
result = yield result = yield
end end
QA::Runtime::Logger.debug("ended wait_until") QA::Runtime::Logger.debug("ended wait_until") if log
result result
end end
......
...@@ -381,5 +381,35 @@ describe QA::Support::Repeater do ...@@ -381,5 +381,35 @@ describe QA::Support::Repeater do
end end
end end
end end
it 'logs attempts' do
attempted = false
expect do
subject.repeat_until(max_attempts: 1) do
unless attempted
attempted = true
break false
end
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
true
end
end.not_to output.to_stdout_from_any_process
end
end end
end end
...@@ -34,6 +34,11 @@ describe QA::Support::Waiter do ...@@ -34,6 +34,11 @@ describe QA::Support::Waiter do
end end
end end
it 'allows logs to be silenced' do
expect { subject.wait_until(max_duration: 0, raise_on_failure: false, log: false) { false } }
.not_to output.to_stdout_from_any_process
end
it 'sets max_duration to 60 by default' do it 'sets max_duration to 60 by default' do
expect(subject).to receive(:repeat_until).with(hash_including(max_duration: 60)) expect(subject).to receive(:repeat_until).with(hash_including(max_duration: 60))
......
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