diff --git a/test/parallel/test-net-keepalive.js b/test/parallel/test-net-keepalive.js index efbbc5ea7986bb..b05537ba052e10 100644 --- a/test/parallel/test-net-keepalive.js +++ b/test/parallel/test-net-keepalive.js @@ -4,8 +4,17 @@ var assert = require('assert'); var net = require('net'); var serverConnection; +var clientConnection; var echoServer = net.createServer(function(connection) { serverConnection = connection; + setTimeout(function() { + // make sure both connections are still open + assert.equal(serverConnection.readyState, 'open'); + assert.equal(clientConnection.readyState, 'open'); + serverConnection.end(); + clientConnection.end(); + echoServer.close(); + }, common.platformTimeout(100)); connection.setTimeout(0); assert.notEqual(connection.setKeepAlive, undefined); // send a keepalive packet after 50 ms @@ -17,15 +26,6 @@ var echoServer = net.createServer(function(connection) { echoServer.listen(common.PORT); echoServer.on('listening', function() { - var clientConnection = net.createConnection(common.PORT); + clientConnection = net.createConnection(common.PORT); clientConnection.setTimeout(0); - - setTimeout(function() { - // make sure both connections are still open - assert.equal(serverConnection.readyState, 'open'); - assert.equal(clientConnection.readyState, 'open'); - serverConnection.end(); - clientConnection.end(); - echoServer.close(); - }, common.platformTimeout(100)); });