node/test/parallel/test-net-socket-local-address.js
Joe Shindelar 2505f05ce8
test: fix order of arguments passed to strictEqual
The argument order in the strictEqual check was in the wrong order.
The first argument is now the actual value and the second argument is
the expected value.

PR-URL: https://github.com/nodejs/node/pull/23571
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Gireesh Punathil <gpunathi@in.ibm.com>
Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
2018-10-15 15:34:45 +02:00

42 lines
964 B
JavaScript

'use strict';
const common = require('../common');
// skip test in FreeBSD jails
if (common.inFreeBSDJail)
common.skip('In a FreeBSD jail');
const assert = require('assert');
const net = require('net');
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(() => {
// client and server should agree on the ports used
assert.deepStrictEqual(serverRemotePorts, clientLocalPorts);
assert.strictEqual(conns, 2);
}));
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);
})
);
}