node/test/parallel/test-net-socket-local-address.js
Jeremiah Senkpiel 52bae222a3 test: abstract skip functionality to common
The tap skipping output is so prevalent yet obscure in nature that we
ought to move it into it's own function in test/common.js

PR-URL: https://github.com/nodejs/node/pull/6697
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
2016-05-12 16:43:35 -04:00

41 lines
953 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;
}
var conns = 0;
var clientLocalPorts = [];
var 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(common.PORT, common.localhostIPv4, connect);
function connect() {
if (conns === 2) {
server.close();
return;
}
conns++;
client.once('close', connect);
client.connect(common.PORT, common.localhostIPv4, () => {
clientLocalPorts.push(client.localPort);
});
}