test(debugger): fix race condition in test helpers#7394
Conversation
Prevent event listeners in setupAssertionListeners from firing multiple times and overwriting trace IDs. The 'message' listener now removes itself after capturing the first valid span, and the 'debugger-input' listener uses .once() instead of .on(). This fixes flaky test failures where subsequent HTTP requests would update the traceId/spanId variables, causing assertion mismatches.
Overall package sizeSelf size: 4.49 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 2.0.3 | 76.87 kB | 808.03 kB | | dc-polyfill | 0.1.10 | 26.73 kB | 26.73 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
|
BenchmarksBenchmark execution time: 2026-01-30 11:44:44 Comparing candidate commit bc68e94 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 226 metrics, 34 unstable metrics. |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #7394 +/- ##
==========================================
- Coverage 86.07% 85.72% -0.36%
==========================================
Files 510 518 +8
Lines 22102 22374 +272
==========================================
+ Hits 19025 19180 +155
- Misses 3077 3194 +117 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Sentry. 🚀 New features to boost your workflow:
|
Prevent event listeners in setupAssertionListeners from firing multiple times and overwriting trace IDs. The 'message' listener now removes itself after capturing the first valid span, and the 'debugger-input' listener uses .once() instead of .on(). This fixes flaky test failures where subsequent HTTP requests would update the traceId/spanId variables, causing assertion mismatches.
Prevent event listeners in setupAssertionListeners from firing multiple times and overwriting trace IDs. The 'message' listener now removes itself after capturing the first valid span, and the 'debugger-input' listener uses .once() instead of .on(). This fixes flaky test failures where subsequent HTTP requests would update the traceId/spanId variables, causing assertion mismatches.
Prevent event listeners in setupAssertionListeners from firing multiple times and overwriting trace IDs. The 'message' listener now removes itself after capturing the first valid span, and the 'debugger-input' listener uses .once() instead of .on(). This fixes flaky test failures where subsequent HTTP requests would update the traceId/spanId variables, causing assertion mismatches.

What does this PR do?
Attempt to fix a race condition in the debugger integration test helper function
setupAssertionListenersthat was likely causing flaky test failures in CI, particularly the testDD_TRACING_ENABLED=true, DD_TRACE_128_BIT_TRACEID_GENERATION_ENABLED=false→should capture and send expected payload when a log line probe is triggered.The fix:
'message'listener now removes itself immediately after capturing the first valid span witht.agent.removeListener('message', messageListener)'debugger-input'listener now uses.once()instead of.on()since we expect exactly one debugger payload per testMotivation
The test was failing intermittently with trace ID mismatches like:
The root cause seems to be that event listeners were using
.on()and persisting across multiple events. When multiple HTTP requests occurred (from background activity or timing variations), the'message'listener would fire multiple times, updating the shared closure variables (traceId,spanId) with values from different requests. This caused assertions to compare trace IDs from mismatched requests.