2015-07-02 15:26:21 -07:00
|
|
|
'use strict';
|
2015-11-23 16:01:35 -08:00
|
|
|
const common = require('../common');
|
2019-03-22 03:44:26 +01:00
|
|
|
// Skip test in FreeBSD jails
|
2017-07-01 02:29:09 +03:00
|
|
|
if (common.inFreeBSDJail)
|
2016-05-11 15:34:52 -04:00
|
|
|
common.skip('In a FreeBSD jail');
|
2017-07-01 02:29:09 +03:00
|
|
|
|
|
|
|
const assert = require('assert');
|
|
|
|
const net = require('net');
|
2015-07-02 15:26:21 -07:00
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
let conns = 0;
|
|
|
|
const clientLocalPorts = [];
|
|
|
|
const serverRemotePorts = [];
|
2016-01-12 12:18:40 -05:00
|
|
|
const client = new net.Socket();
|
2016-01-28 10:21:57 -05:00
|
|
|
const server = net.createServer((socket) => {
|
2015-07-02 15:26:21 -07:00
|
|
|
serverRemotePorts.push(socket.remotePort);
|
2016-01-12 12:18:40 -05:00
|
|
|
socket.end();
|
2015-07-02 15:26:21 -07:00
|
|
|
});
|
|
|
|
|
2016-01-12 12:18:40 -05:00
|
|
|
server.on('close', common.mustCall(() => {
|
2019-01-21 01:22:27 +01:00
|
|
|
// Client and server should agree on the ports used
|
2018-10-12 11:03:15 -07:00
|
|
|
assert.deepStrictEqual(serverRemotePorts, clientLocalPorts);
|
|
|
|
assert.strictEqual(conns, 2);
|
2015-11-23 16:01:35 -08:00
|
|
|
}));
|
2015-07-02 15:26:21 -07:00
|
|
|
|
2016-05-29 03:06:56 -04:00
|
|
|
server.listen(0, common.localhostIPv4, connect);
|
2015-07-02 15:26:21 -07:00
|
|
|
|
2016-01-12 12:18:40 -05:00
|
|
|
function connect() {
|
|
|
|
if (conns === 2) {
|
|
|
|
server.close();
|
2015-12-01 13:13:40 -08:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
conns++;
|
2016-01-12 12:18:40 -05:00
|
|
|
client.once('close', connect);
|
2017-06-07 12:49:00 -07:00
|
|
|
assert.strictEqual(
|
|
|
|
client,
|
|
|
|
client.connect(server.address().port, common.localhostIPv4, () => {
|
|
|
|
clientLocalPorts.push(client.localPort);
|
|
|
|
})
|
|
|
|
);
|
2015-07-02 15:26:21 -07:00
|
|
|
}
|