From c8d535111c2eabbd9ec7601b67f7f8a83f9496c2 Mon Sep 17 00:00:00 2001 From: Ivo Anjo Date: Fri, 20 Sep 2024 11:49:24 +0100 Subject: [PATCH] [NO-TICKET] Fix flaky spec in profiler due to race **What does this PR do?** This PR fixes a flaky spec introduced by #3929: a spec to check that an error was raised in a background thread implicitly depended on a race (that the background thread ran before the rspec thread did) and thus started failing when the race was lost. By actually synchronizing with the background thread using the `on_failure_proc`, we now guarantee that the background thread has the chance to run as expected. **Motivation:** Our goal is to always have zero flaky specs in the profiler! **Additional Notes:** Fixes https://github.com/DataDog/ruby-guild/issues/179 **How to test the change?** Validate that CI is still green. --- .../profiling/collectors/cpu_and_wall_time_worker_spec.rb | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/spec/datadog/profiling/collectors/cpu_and_wall_time_worker_spec.rb b/spec/datadog/profiling/collectors/cpu_and_wall_time_worker_spec.rb index c39971c3f23..b93765fbecb 100644 --- a/spec/datadog/profiling/collectors/cpu_and_wall_time_worker_spec.rb +++ b/spec/datadog/profiling/collectors/cpu_and_wall_time_worker_spec.rb @@ -155,8 +155,11 @@ it do expect(Datadog.logger).to receive(:warn).with(/GVL profiling is not supported/) + proc_called = Queue.new - cpu_and_wall_time_worker.start + cpu_and_wall_time_worker.start(on_failure_proc: proc { proc_called << true }) + + proc_called.pop end end