Skip to content

Commit a42a2ba

Browse files
authored
chore(ddtrace/tracer): fix flaky TestHealthMetricsRaceCondition (#3971)
1 parent ce9b743 commit a42a2ba

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed

ddtrace/tracer/metrics_test.go

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -246,14 +246,16 @@ func TestHealthMetricsRaceCondition(t *testing.T) {
246246
sp.Finish()
247247
}()
248248
}
249-
time.Sleep(150 * time.Millisecond)
250-
flush(5)
251-
tg.Wait(assert, 10, 100*time.Millisecond)
252249
wg.Wait()
250+
flush(5)
253251

254-
counts := tg.Counts()
255-
assert.Equal(int64(5), counts["datadog.tracer.spans_started"])
256-
assert.Equal(int64(5), counts["datadog.tracer.spans_finished"])
252+
cond := func() bool {
253+
counts := tg.Counts()
254+
return counts["datadog.tracer.spans_started"] == 5 && counts["datadog.tracer.spans_finished"] == 5
255+
}
256+
assert.Eventually(cond, 5*time.Second, time.Millisecond)
257+
time.Sleep(10 * time.Millisecond)
258+
assert.True(cond())
257259

258260
assertSpanMetricCountsAreZero(t, tracer.spansStarted)
259261
assertSpanMetricCountsAreZero(t, tracer.spansFinished)

0 commit comments

Comments
 (0)