From 9a3f91df6b5a1ae1afe1a0f1bdfdbe3c15d39e19 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 8 Jan 2025 00:29:13 -0500 Subject: [PATCH 1/3] Report timing information if try_wait_until times out --- spec/support/synchronization_helpers.rb | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/spec/support/synchronization_helpers.rb b/spec/support/synchronization_helpers.rb index 0a1d52f7cad..3790a194603 100644 --- a/spec/support/synchronization_helpers.rb +++ b/spec/support/synchronization_helpers.rb @@ -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 @@ -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. # @@ -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}" + + raise("Wait time exhausted! Requested: #{spec}, waited: #{actual}") end def test_repeat From 4382b44fff5968ab2c6495e12e173018f13e7950 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 8 Jan 2025 00:31:47 -0500 Subject: [PATCH 2/3] rubocop --- spec/support/synchronization_helpers.rb | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/spec/support/synchronization_helpers.rb b/spec/support/synchronization_helpers.rb index 3790a194603..127a55331ea 100644 --- a/spec/support/synchronization_helpers.rb +++ b/spec/support/synchronization_helpers.rb @@ -67,12 +67,12 @@ 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 + "#{seconds} seconds" + elsif attempts || backoff + "#{attempts} attempts with backoff #{backoff}" + else + 'none' + end if seconds attempts = seconds * 10 From 1d1b6db3aba5d162d4a7ab3e38e5d21122f433c4 Mon Sep 17 00:00:00 2001 From: Oleg Pudeyev Date: Wed, 8 Jan 2025 00:32:36 -0500 Subject: [PATCH 3/3] rubocop --- spec/support/synchronization_helpers.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/spec/support/synchronization_helpers.rb b/spec/support/synchronization_helpers.rb index 127a55331ea..0fbae1906b1 100644 --- a/spec/support/synchronization_helpers.rb +++ b/spec/support/synchronization_helpers.rb @@ -105,7 +105,7 @@ def try_wait_until(seconds: nil, attempts: nil, backoff: nil) end elapsed = Datadog::Core::Utils::Time.get_time - start_time - actual = "#{'%.2f' % elapsed} seconds, #{attempts} attempts with backoff #{backoff}" + actual = "#{'%.2f' % elapsed} seconds, #{attempts} attempts with backoff #{backoff}" # rubocop:disable Style/FormatString raise("Wait time exhausted! Requested: #{spec}, waited: #{actual}") end