test(ws): refactor lifecycle hooks to use dynamic ports and separate afterEach - #8367
Conversation
…afterEach - Replace hardcoded ports (6015, 16015) with port 0 so the kernel assigns an available port, eliminating inter-run port conflicts - Move regression-test resource cleanup (server, socket) from test bodies into dedicated afterEach hooks - Split combined afterEach callbacks into one hook per concern so a failure in one cleanup step doesn't skip the others - Load/close the agent in beforeEach/afterEach instead of before/after so each test gets a clean agent state Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Overall package sizeSelf size: 5.8 MB Dependency sizes| name | version | self size | total size | |------|---------|-----------|------------| | import-in-the-middle | 3.0.1 | 82.56 kB | 817.39 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!❄️ No new flaky tests detected 🎯 Code Coverage (details) 🔗 Commit SHA: bb58141 | Docs | Datadog PR Page | Give us feedback! |
BenchmarksBenchmark execution time: 2026-05-09 10:50:40 Comparing candidate commit bb58141 in PR branch Found 0 performance improvements and 0 performance regressions! Performance is the same for 1732 metrics, 112 unstable metrics. |
|
|
||
| const dc = require('dc-polyfill') | ||
| const { after, afterEach, before, beforeEach, describe, it } = require('mocha') | ||
| const setSocketCh = dc.channel('tracing:ws:server:connect:setSocket') |
There was a problem hiding this comment.
Non-blocking, but with DataDog/dc-polyfill#27 this isn't really needed anymore
There was a problem hiding this comment.
That is indeed redundant from a fix perspective, but it's still good practice to call channel only once at the top, so no harm in keeping it like that.
…afterEach (#8367) - Replace hardcoded ports (6015, 16015) with port 0 so the kernel assigns an available port, eliminating inter-run port conflicts - Move regression-test resource cleanup (server, socket) from test bodies into dedicated afterEach hooks - Split combined afterEach callbacks into one hook per concern so a failure in one cleanup step doesn't skip the others - Load/close the agent in beforeEach/afterEach instead of before/after so each test gets a clean agent state - Move channel declaration to top of file --------- Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
…afterEach (#8367) - Replace hardcoded ports (6015, 16015) with port 0 so the kernel assigns an available port, eliminating inter-run port conflicts - Move regression-test resource cleanup (server, socket) from test bodies into dedicated afterEach hooks - Split combined afterEach callbacks into one hook per concern so a failure in one cleanup step doesn't skip the others - Load/close the agent in beforeEach/afterEach instead of before/after so each test gets a clean agent state - Move channel declaration to top of file --------- Co-authored-by: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
Summary
port: 0so the kernel assigns an available port, eliminating inter-run conflictsafterEachhooksafterEachcallbacks into one hook per concern so a failure in one cleanup step doesn't prevent others from runningbeforeEach/afterEachinstead ofbefore/afterso each test gets a clean agent statedc.channel(...)declaration to the top of the fileTest plan
PLUGINS=ws npm run test:pluginspasses