Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion spec/support/synchronization_helpers.rb
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,14 @@ def expect_in_fork(fork_expectations: nil, timeout_seconds: 10)
def try_wait_until(seconds: nil, attempts: nil, backoff: nil)
raise 'Provider either `seconds` or `attempts` & `backoff`, not both' if seconds && (attempts || backoff)

spec = if seconds
"#{seconds} seconds"
elsif attempts || backoff
"#{attempts} attempts with backoff #{backoff}"
else
'none'
end

if seconds
attempts = seconds * 10
backoff = 0.1
Expand All @@ -75,6 +83,8 @@ def try_wait_until(seconds: nil, attempts: nil, backoff: nil)
backoff ||= 0.1
end

start_time = Datadog::Core::Utils::Time.get_time

# It's common for tests to want to run simple tasks in a background thread
# but call this method without the thread having even time to start.
#
Expand All @@ -94,7 +104,10 @@ def try_wait_until(seconds: nil, attempts: nil, backoff: nil)
end
end

raise('Wait time exhausted!')
elapsed = Datadog::Core::Utils::Time.get_time - start_time
actual = "#{'%.2f' % elapsed} seconds, #{attempts} attempts with backoff #{backoff}" # rubocop:disable Style/FormatString

raise("Wait time exhausted! Requested: #{spec}, waited: #{actual}")
end

def test_repeat
Expand Down
Loading