mirror of
https://github.com/zebrajr/node.git
synced 2025-12-07 00:20:38 +01:00
Also, add tests to ensure they will always return this, and to confirm they return this when these doc changes are back-ported to earlier release lines. PR-URL: https://github.com/nodejs/node/pull/13531 Reviewed-By: Gibson Fahnestock <gibfahn@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
44 lines
1001 B
JavaScript
44 lines
1001 B
JavaScript
'use strict';
|
|
const common = require('../common');
|
|
const assert = require('assert');
|
|
const net = require('net');
|
|
|
|
// skip test in FreeBSD jails
|
|
if (common.inFreeBSDJail) {
|
|
common.skip('In a FreeBSD jail');
|
|
return;
|
|
}
|
|
|
|
let conns = 0;
|
|
const clientLocalPorts = [];
|
|
const serverRemotePorts = [];
|
|
const client = new net.Socket();
|
|
const server = net.createServer((socket) => {
|
|
serverRemotePorts.push(socket.remotePort);
|
|
socket.end();
|
|
});
|
|
|
|
server.on('close', common.mustCall(() => {
|
|
assert.deepStrictEqual(clientLocalPorts, serverRemotePorts,
|
|
'client and server should agree on the ports used');
|
|
assert.strictEqual(2, conns);
|
|
}));
|
|
|
|
server.listen(0, common.localhostIPv4, connect);
|
|
|
|
function connect() {
|
|
if (conns === 2) {
|
|
server.close();
|
|
return;
|
|
}
|
|
|
|
conns++;
|
|
client.once('close', connect);
|
|
assert.strictEqual(
|
|
client,
|
|
client.connect(server.address().port, common.localhostIPv4, () => {
|
|
clientLocalPorts.push(client.localPort);
|
|
})
|
|
);
|
|
}
|