Skip to content

Commit

Permalink
test: fix parallel/test-net-socket-local-address
Browse files Browse the repository at this point in the history
Fix flakiness where the client sometimes closed the server before the
server had the chance to process the outstanding client connection.
Make the server close itself instead.

Fixes: nodejs#2475
  • Loading branch information
bnoordhuis committed Dec 1, 2015
1 parent e5d97fd commit 840e533
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 7 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
10 changes: 4 additions & 6 deletions test/parallel/test-net-socket-local-address.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,21 @@ var serverRemotePorts = [];

const server = net.createServer(function(socket) {
serverRemotePorts.push(socket.remotePort);
conns++;
if (++conns === 2) this.close();
});

const client = new net.Socket();

server.on('close', common.mustCall(function() {
process.on('exit', function() {
assert.deepEqual(clientLocalPorts, serverRemotePorts,
'client and server should agree on the ports used');
assert.equal(2, conns);
}));
});

server.listen(common.PORT, common.localhostIPv4, testConnect);

function testConnect() {
if (conns == 2) {
return server.close();
}
if (conns >= 2) return;
client.connect(common.PORT, common.localhostIPv4, function() {
clientLocalPorts.push(this.localPort);
this.once('close', testConnect);
Expand Down

0 comments on commit 840e533

Please sign in to comment.