0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-21 21:19:50 +01:00
nodejs/test/parallel/test-net-connect-reset-until-connected.js
Vita Batrla 21fcfcdd5d
test: fix test-net-connect-reset-until-connected
Fixes: https://github.com/nodejs/node/issues/43446
PR-URL: https://github.com/nodejs/node/pull/46781
Reviewed-By: theanarkh <theratliter@gmail.com>
Reviewed-By: Richard Lau <rlau@redhat.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
2023-02-25 18:53:11 +00:00

30 lines
685 B
JavaScript

'use strict';
const common = require('../common');
const net = require('net');
function barrier(count, cb) {
return function() {
if (--count === 0)
cb();
};
}
const server = net.createServer();
server.listen(0, common.mustCall(function() {
const port = server.address().port;
const conn = net.createConnection(port);
const connok = barrier(2, () => conn.resetAndDestroy());
conn.on('close', common.mustCall());
server.on('connection', (socket) => {
connok();
socket.on('error', common.expectsError({
code: 'ECONNRESET',
message: 'read ECONNRESET',
name: 'Error'
}));
server.close();
});
conn.on('connect', connok);
}));