Skip to content

Commit

Permalink
[test] Fix flaky test
Browse files Browse the repository at this point in the history
  • Loading branch information
lpinca committed Dec 8, 2023
1 parent a049674 commit 726abc3
Showing 1 changed file with 8 additions and 6 deletions.
14 changes: 8 additions & 6 deletions test/websocket.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -626,25 +626,27 @@ describe('WebSocket', () => {
});
});

it('does not re-emit `net.Socket` errors', (done) => {
const codes = ['EPIPE', 'ECONNABORTED', 'ECANCELED', 'ECONNRESET'];
it('does not re-emit `net.Socket` errors', function (done) {
//
// `socket.resetAndDestroy()` is not available in Node.js < 16.17.0.
//
if (process.versions.modules < 93) return this.skip();

const wss = new WebSocket.Server({ port: 0 }, () => {
const ws = new WebSocket(`ws://localhost:${wss.address().port}`);

ws.on('open', () => {
ws._socket.on('error', (err) => {
assert.ok(err instanceof Error);
assert.ok(codes.includes(err.code), `Unexpected code: ${err.code}`);
assert.strictEqual(err.code, 'ECONNRESET');
ws.on('close', (code, message) => {
assert.strictEqual(code, 1006);
assert.strictEqual(message, EMPTY_BUFFER);
wss.close(done);
});
});

for (const client of wss.clients) client.terminate();
ws.send('foo');
ws.send('bar');
wss.clients.values().next().value._socket.resetAndDestroy();
});
});
});
Expand Down

0 comments on commit 726abc3

Please sign in to comment.