Browse Source

test: fix flaky test-net-socket-local-address

test-net-socket-local-address had a race condition that resulted in
unreliability on FreeBSD and Windows. This changes fixes the issue.

Fixes: https://github.com/nodejs/node/issues/2475
PR-URL: https://github.com/nodejs/node/pull/4109
Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Reviewed-By: Evan Lucas <evanlucas@me.com>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
v4.x
Rich Trott 9 years ago
committed by Myles Borins
parent
commit
c9100d78f3
  1. 1
      test/parallel/parallel.status
  2. 10
      test/parallel/test-net-socket-local-address.js

1
test/parallel/parallel.status

@ -22,4 +22,3 @@ test-child-process-exit-code : PASS,FLAKY
test-debug-signal-cluster : PASS,FLAKY
[$system==freebsd]
test-net-socket-local-address : PASS,FLAKY

10
test/parallel/test-net-socket-local-address.js

@ -15,7 +15,7 @@ var serverRemotePorts = [];
const server = net.createServer(function(socket) {
serverRemotePorts.push(socket.remotePort);
conns++;
testConnect();
});
const client = new net.Socket();
@ -29,7 +29,12 @@ server.on('close', common.mustCall(function() {
server.listen(common.PORT, common.localhostIPv4, testConnect);
function testConnect() {
if (conns == 2) {
if (conns > serverRemotePorts.length || conns > clientLocalPorts.length) {
// We're waiting for a callback to fire.
return;
}
if (conns === 2) {
return server.close();
}
client.connect(common.PORT, common.localhostIPv4, function() {
@ -37,4 +42,5 @@ function testConnect() {
this.once('close', testConnect);
this.destroy();
});
conns++;
}

Loading…
Cancel
Save