From 840e53308313fa2dce406598e8465438d187034b Mon Sep 17 00:00:00 2001 From: Ben Noordhuis Date: Tue, 1 Dec 2015 00:20:48 +0100 Subject: [PATCH] test: fix parallel/test-net-socket-local-address 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: https://github.com/nodejs/node/issues/2475 --- test/parallel/parallel.status | 1 - test/parallel/test-net-socket-local-address.js | 10 ++++------ 2 files changed, 4 insertions(+), 7 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..36c0eb66789aeb 100644 --- a/test/parallel/test-net-socket-local-address.js +++ b/test/parallel/test-net-socket-local-address.js @@ -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);