test(test-optimization): handle 5xx retry in getKnownTests error test#9110
Conversation
The request helper retries once on a 5xx with a 5–7.5 s jittered delay, but the getKnownTests "should return an error if the request fails" test mocked a single 500 interceptor and used real timers. The retried request had no interceptor and its retry timer always exceeded mocha's 5 s timeout, so the callback never fired and the test timed out. Collapse the retry delay to 0 ms and add a second 500 interceptor so the test exercises the real retry path and asserts both requests are consumed.
Overall package sizeSelf size: 6.39 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.2.0 | 104.26 kB | 843.44 kB | | opentracing | 0.14.7 | 194.81 kB | 194.81 kB | | dc-polyfill | 0.1.11 | 25.74 kB | 25.74 kB |🤖 This report was automatically generated by heaviest-objects-in-the-universe |
🎉 All green!🧪 All tests passed 🎯 Code Coverage (details) 🔗 Commit SHA: f08c4ef | Docs | Datadog PR Page | Give us feedback! |
Codecov Report✅ All modified and coverable lines are covered by tests. Additional details and impacted files@@ Coverage Diff @@
## master #9110 +/- ##
=======================================
Coverage 93.69% 93.69%
=======================================
Files 889 889
Lines 50856 50856
Branches 11830 11830
=======================================
+ Hits 47647 47648 +1
+ Misses 3209 3208 -1 Flags with carried forward coverage won't be shown. Click here to find out more. ☔ View full report in Codecov by Harness. 🚀 New features to boost your workflow:
|
There was a problem hiding this comment.
More details
PR fixes a test flake by collapsing the 5-7.5s request retry delay to 0ms in the test stub and adding a second mock interceptor so the retry path completes within mocha's 5s timeout. Test-only change; no production code impact. Pattern matches dedicated request.spec.js tests already in the codebase.
🤖 Datadog Autotest · Commit f08c4ef · What is Autotest? · Any feedback? Reach out in #autotest
BenchmarksBenchmark execution time: 2026-06-27 08:24:47 Comparing candidate commit f08c4ef in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 2252 metrics, 34 unstable metrics.
|
…#9110) The request helper retries once on a 5xx with a 5–7.5 s jittered delay, but the getKnownTests "should return an error if the request fails" test mocked a single 500 interceptor and used real timers. The retried request had no interceptor and its retry timer always exceeded mocha's 5 s timeout, so the callback never fired and the test timed out. Collapse the retry delay to 0 ms and add a second 500 interceptor so the test exercises the real retry path and asserts both requests are consumed.
…#9110) The request helper retries once on a 5xx with a 5–7.5 s jittered delay, but the getKnownTests "should return an error if the request fails" test mocked a single 500 interceptor and used real timers. The retried request had no interceptor and its retry timer always exceeded mocha's 5 s timeout, so the callback never fired and the test timed out. Collapse the retry delay to 0 ms and add a second 500 interceptor so the test exercises the real retry path and asserts both requests are consumed.
Summary
The
getKnownTests"should return an error if the request fails" test timedout on a clean
master. The request helper retries once on a 5xx with a5–7.5 s jittered delay, but the test mocked a single
500interceptor and usedreal timers. The retried request had no interceptor and its retry timer always
exceeded mocha's 5 s timeout, so the callback never fired.
The fix collapses the retry delay to 0 ms (the same
setTimeoutstub thededicated
request.spec.jsalready uses) and adds a second500interceptor,so the test exercises the real retry path and asserts both requests are
consumed. No production code changes.
Test plan
./node_modules/.bin/mocha packages/dd-trace/test/ci-visibility/exporters/ci-visibility-exporter.spec.js --grep "getKnownTests"→ 10 passing (was 9 passing, 1 failing on master).