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
RetriesExceededError = 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
start = Time.now
begin
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
return result if result
......
......@@ -6,7 +6,7 @@ module QA
module_function
def wait_for_requests
Waiter.wait_until do
Waiter.wait_until(log: false) do
finished_all_ajax_requests? && finished_all_axios_requests?
end
end
......
......@@ -7,15 +7,17 @@ module QA
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)
QA::Runtime::Logger.debug(
<<~MSG.tr("\n", ' ')
with wait_until: max_duration: #{max_duration};
reload_page: #{reload_page};
sleep_interval: #{sleep_interval};
raise_on_failure: #{raise_on_failure}
MSG
)
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)
if log
QA::Runtime::Logger.debug(
<<~MSG.tr("\n", ' ')
with wait_until: max_duration: #{max_duration};
reload_page: #{reload_page};
sleep_interval: #{sleep_interval};
raise_on_failure: #{raise_on_failure}
MSG
)
end
result = nil
self.repeat_until(
......@@ -23,11 +25,12 @@ module QA
reload_page: reload_page,
sleep_interval: sleep_interval,
raise_on_failure: raise_on_failure,
retry_on_exception: retry_on_exception
retry_on_exception: retry_on_exception,
log: log
) do
result = yield
end
QA::Runtime::Logger.debug("ended wait_until")
QA::Runtime::Logger.debug("ended wait_until") if log
result
end
......
......@@ -381,5 +381,35 @@ describe QA::Support::Repeater do
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
......@@ -34,6 +34,11 @@ describe QA::Support::Waiter do
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
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