diff --git a/spec/datadog/tracing/integration_spec.rb b/spec/datadog/tracing/integration_spec.rb index 9b6b88d251..52737af434 100644 --- a/spec/datadog/tracing/integration_spec.rb +++ b/spec/datadog/tracing/integration_spec.rb @@ -595,6 +595,13 @@ def agent_receives_span_step3(previous_success) span.service = 'my.service' end + # The background worker flushes nearly instantly (DEFAULT_FLUSH_INTERVAL + # is stubbed to 0), so the trace is almost always already flushed before + # shutdown threads start. Make that deterministic to avoid flakiness when + # the 1-second DEFAULT_SHUTDOWN_TIMEOUT is occasionally too short for the + # HTTP round-trip under CI load. + try_wait_until { tracer.writer.stats[:traces_flushed] >= 1 } + threads = Array.new(10) do Thread.new { tracer.shutdown! } end