Skip to content

Commit 726abc3

Browse files
committedDec 8, 2023
[test] Fix flaky test
1 parent a049674 commit 726abc3

File tree

1 file changed

+8
-6
lines changed

1 file changed

+8
-6
lines changed
 

‎test/websocket.test.js

+8-6
Original file line numberDiff line numberDiff line change
@@ -626,25 +626,27 @@ describe('WebSocket', () => {
626626
});
627627
});
628628

629-
it('does not re-emit `net.Socket` errors', (done) => {
630-
const codes = ['EPIPE', 'ECONNABORTED', 'ECANCELED', 'ECONNRESET'];
629+
it('does not re-emit `net.Socket` errors', function (done) {
630+
//
631+
// `socket.resetAndDestroy()` is not available in Node.js < 16.17.0.
632+
//
633+
if (process.versions.modules < 93) return this.skip();
634+
631635
const wss = new WebSocket.Server({ port: 0 }, () => {
632636
const ws = new WebSocket(`ws://localhost:${wss.address().port}`);
633637

634638
ws.on('open', () => {
635639
ws._socket.on('error', (err) => {
636640
assert.ok(err instanceof Error);
637-
assert.ok(codes.includes(err.code), `Unexpected code: ${err.code}`);
641+
assert.strictEqual(err.code, 'ECONNRESET');
638642
ws.on('close', (code, message) => {
639643
assert.strictEqual(code, 1006);
640644
assert.strictEqual(message, EMPTY_BUFFER);
641645
wss.close(done);
642646
});
643647
});
644648

645-
for (const client of wss.clients) client.terminate();
646-
ws.send('foo');
647-
ws.send('bar');
649+
wss.clients.values().next().value._socket.resetAndDestroy();
648650
});
649651
});
650652
});

0 commit comments

Comments
 (0)
Please sign in to comment.