|
3 | 3 | const assert = require('node:assert') |
4 | 4 | const { once } = require('node:events') |
5 | 5 |
|
| 6 | +const dc = require('dc-polyfill') |
6 | 7 | const { after, afterEach, before, beforeEach, describe, it } = require('mocha') |
7 | 8 |
|
8 | 9 | const agent = require('../../dd-trace/test/plugins/agent') |
| 10 | +const { storage } = require('../../datadog-core') |
9 | 11 | const { withVersions } = require('../../dd-trace/test/setup/mocha') |
10 | 12 | const { assertObjectContains } = require('../../../integration-tests/helpers') |
11 | 13 |
|
@@ -65,6 +67,29 @@ describe('Plugin', () => { |
65 | 67 | agent.close({ ritmReset: false, wipe: true }) |
66 | 68 | }) |
67 | 69 |
|
| 70 | + it('should not retain the connection span during socket setup', async () => { |
| 71 | + const setSocketCh = dc.channel('tracing:ws:server:connect:setSocket') |
| 72 | + let resolve |
| 73 | + const promise = new Promise((_resolve) => { |
| 74 | + resolve = _resolve |
| 75 | + }) |
| 76 | + |
| 77 | + const handler = () => { |
| 78 | + resolve(storage('legacy').getStore()) |
| 79 | + setSocketCh.unsubscribe(handler) |
| 80 | + } |
| 81 | + setSocketCh.subscribe(handler) |
| 82 | + |
| 83 | + // Trigger setSocket |
| 84 | + const newClient = new WebSocket(`ws://localhost:${clientPort}/test`) |
| 85 | + newClient.on('open', () => newClient.close()) |
| 86 | + |
| 87 | + const store = await promise |
| 88 | + |
| 89 | + assert.strictEqual(store?.span, undefined, |
| 90 | + 'connection span should not be in the store during setSocket') |
| 91 | + }) |
| 92 | + |
68 | 93 | it('should do automatic instrumentation and remove broken handler', () => { |
69 | 94 | wsServer.on('connection', (ws) => { |
70 | 95 | connectionReceived = true |
|
0 commit comments