From 6dbc8a876a82cef2d4a5944ef71fd9faf12b2a0b Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 1 Dec 2015 13:13:40 -0800 Subject: [PATCH 1/5] 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 --- test/parallel/parallel.status | 1 - .../parallel/test-net-socket-local-address.js | 19 ++++++++++++------- 2 files changed, 12 insertions(+), 8 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..b29cc41c71a199 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,12 +29,17 @@ server.on('close', common.mustCall(function() { server.listen(common.PORT, common.localhostIPv4, testConnect); function testConnect() { - if (conns == 2) { + if (conns === 2) { return server.close(); } - client.connect(common.PORT, common.localhostIPv4, function() { - clientLocalPorts.push(this.localPort); - this.once('close', testConnect); - this.destroy(); - }); + // conns === clientLocalPorts.length means both server and client callbacks + // have fired + if (conns === clientLocalPorts.length) { + client.connect(common.PORT, common.localhostIPv4, function() { + clientLocalPorts.push(this.localPort); + this.once('close', testConnect); + this.destroy(); + }); + } + conns++; } From 93211bceaa12ab8aeabb65305329b7c07de2e9c6 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 1 Dec 2015 13:55:49 -0800 Subject: [PATCH 2/5] fixup --- test/parallel/test-net-socket-local-address.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/test/parallel/test-net-socket-local-address.js b/test/parallel/test-net-socket-local-address.js index b29cc41c71a199..b682c6a9d1e393 100644 --- a/test/parallel/test-net-socket-local-address.js +++ b/test/parallel/test-net-socket-local-address.js @@ -32,9 +32,9 @@ function testConnect() { if (conns === 2) { return server.close(); } - // conns === clientLocalPorts.length means both server and client callbacks - // have fired - if (conns === clientLocalPorts.length) { + // If both server and client callbacks have fired... + if (serverRemotePorts.length === clientLocalPorts.length) { + // ...then proceed. client.connect(common.PORT, common.localhostIPv4, function() { clientLocalPorts.push(this.localPort); this.once('close', testConnect); From d9ceff6aeda3c2202d869328eac3c588348e4ee6 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 1 Dec 2015 14:10:59 -0800 Subject: [PATCH 3/5] fixup --- test/parallel/test-net-socket-local-address.js | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-net-socket-local-address.js b/test/parallel/test-net-socket-local-address.js index b682c6a9d1e393..9070af05ebbb39 100644 --- a/test/parallel/test-net-socket-local-address.js +++ b/test/parallel/test-net-socket-local-address.js @@ -29,17 +29,17 @@ server.on('close', common.mustCall(function() { server.listen(common.PORT, common.localhostIPv4, testConnect); function testConnect() { - if (conns === 2) { - return server.close(); - } - // If both server and client callbacks have fired... + // If we're not waiting for a server or client callback to fire... if (serverRemotePorts.length === clientLocalPorts.length) { // ...then proceed. + if (conns === 2) { + return server.close(); + } client.connect(common.PORT, common.localhostIPv4, function() { clientLocalPorts.push(this.localPort); this.once('close', testConnect); this.destroy(); }); + conns++; } - conns++; } From 4bb8aaf8cc47db6514e6046306852241a4b201fb Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 1 Dec 2015 14:40:33 -0800 Subject: [PATCH 4/5] fixup --- test/parallel/test-net-socket-local-address.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/parallel/test-net-socket-local-address.js b/test/parallel/test-net-socket-local-address.js index 9070af05ebbb39..689517a683b006 100644 --- a/test/parallel/test-net-socket-local-address.js +++ b/test/parallel/test-net-socket-local-address.js @@ -30,7 +30,7 @@ server.listen(common.PORT, common.localhostIPv4, testConnect); function testConnect() { // If we're not waiting for a server or client callback to fire... - if (serverRemotePorts.length === clientLocalPorts.length) { + if (conns > serverRemotePorts.length || conns > clientLocalPorts.length) { // ...then proceed. if (conns === 2) { return server.close(); From 7e465bd2d2acf1c618a82a499392d40eea6c321c Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Tue, 1 Dec 2015 14:51:00 -0800 Subject: [PATCH 5/5] fixup --- .../parallel/test-net-socket-local-address.js | 23 ++++++++++--------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/test/parallel/test-net-socket-local-address.js b/test/parallel/test-net-socket-local-address.js index 689517a683b006..7e90bd2f79ba47 100644 --- a/test/parallel/test-net-socket-local-address.js +++ b/test/parallel/test-net-socket-local-address.js @@ -29,17 +29,18 @@ server.on('close', common.mustCall(function() { server.listen(common.PORT, common.localhostIPv4, testConnect); function testConnect() { - // If we're not waiting for a server or client callback to fire... if (conns > serverRemotePorts.length || conns > clientLocalPorts.length) { - // ...then proceed. - if (conns === 2) { - return server.close(); - } - client.connect(common.PORT, common.localhostIPv4, function() { - clientLocalPorts.push(this.localPort); - this.once('close', testConnect); - this.destroy(); - }); - conns++; + // We're waiting for a callback to fire. + return; } + + if (conns === 2) { + return server.close(); + } + client.connect(common.PORT, common.localhostIPv4, function() { + clientLocalPorts.push(this.localPort); + this.once('close', testConnect); + this.destroy(); + }); + conns++; }