From c79b145abcd9b05b95103299ba613fb20b489340 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 1 Dec 2015 13:13:40 -0800 Subject: [PATCH] test: fix flaky test-net-socket-local-address MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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 Reviewed-By: Evan Lucas Reviewed-By: Johan Bergström --- test/parallel/parallel.status | 1 - test/parallel/test-net-socket-local-address.js | 10 ++++++++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/test/parallel/parallel.status b/test/parallel/parallel.status index bce36b53bbe5d2..b30ec2a7dc019f 100644 --- a/test/parallel/parallel.status +++ b/test/parallel/parallel.status @@ -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 diff --git a/test/parallel/test-net-socket-local-address.js b/test/parallel/test-net-socket-local-address.js index 502c2d226d54b8..7e90bd2f79ba47 100644 --- a/test/parallel/test-net-socket-local-address.js +++ b/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++; }