Skip to content

Commit

Permalink
test: fix race in test-net-socket-local-address
Browse files Browse the repository at this point in the history
test-net-socket-local-address had a race condition that resulted in
unreliability on FreeBSD. This changes fixes the issue.

Fixes: nodejs#2475
  • Loading branch information
Trott committed Nov 27, 2015
1 parent d1000b4 commit c8b7437
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 2 deletions.
1 change: 0 additions & 1 deletion test/parallel/parallel.status
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,3 @@ test-child-process-exit-code : PASS,FLAKY
[$system==solaris] # Also applies to SmartOS

[$system==freebsd]
test-net-socket-local-address : PASS,FLAKY
13 changes: 12 additions & 1 deletion test/parallel/test-net-socket-local-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,15 @@ if (common.inFreeBSDJail) {
var conns = 0;
var clientLocalPorts = [];
var serverRemotePorts = [];
var serverNeedsToFireConnection = false;

const server = net.createServer(function(socket) {
serverRemotePorts.push(socket.remotePort);
conns++;
if (serverNeedsToFireConnection) {
serverNeedsToFireConnection = false;
testConnect();
}
});

const client = new net.Socket();
Expand All @@ -34,7 +39,13 @@ function testConnect() {
}
client.connect(common.PORT, common.localhostIPv4, function() {
clientLocalPorts.push(this.localPort);
this.once('close', testConnect);
this.once('close', function() {
if (conns === clientLocalPorts.length) {
testConnect();
} else {
serverNeedsToFireConnection = true;
}
});
this.destroy();
});
}

0 comments on commit c8b7437

Please sign in to comment.