diff options
author | Santiago Gimeno <santiago.gimeno@gmail.com> | 2016-01-16 01:54:44 +0100 |
---|---|---|
committer | James M Snell <jasnell@gmail.com> | 2016-02-04 10:03:09 -0800 |
commit | 538813c45547d281e912b0e022f617baf2557791 (patch) | |
tree | f7f5658b7100a91b84cea86da826b1fdf29392ea /test | |
parent | ac0d92e4d128b8675cc94d07e0a73c67c5e0e5f0 (diff) | |
download | node-new-538813c45547d281e912b0e022f617baf2557791.tar.gz |
test: fix `net-socket-timeout-unref` flakiness
From time to time this test is failing in OS X because at least one of
the connections takes quite a long time (around 5 seconds) causing some
of the timers may fire before the test exited. To solve this, wait for
all the connections to be established before setting the timeouts and
unrefing the sockets.
PR-URL: https://github.com/nodejs/node/pull/4772
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test')
-rw-r--r-- | test/parallel/test-net-socket-timeout-unref.js | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/test/parallel/test-net-socket-timeout-unref.js b/test/parallel/test-net-socket-timeout-unref.js index c7e651afef..b7ed0ec344 100644 --- a/test/parallel/test-net-socket-timeout-unref.js +++ b/test/parallel/test-net-socket-timeout-unref.js @@ -11,15 +11,26 @@ server.listen(common.PORT); server.unref(); var timedout = false; +var connections = 0; +var sockets = []; +var delays = [8, 5, 3, 6, 2, 4]; -[8, 5, 3, 6, 2, 4].forEach(function(T) { +delays.forEach(function(T) { var socket = net.createConnection(common.PORT, 'localhost'); - socket.setTimeout(T * 1000, function() { - console.log(process._getActiveHandles()); - timedout = true; - socket.destroy(); + socket.on('connect', function() { + if (++connections === delays.length) { + sockets.forEach(function(s) { + s[0].setTimeout(s[1] * 1000, function() { + timedout = true; + s[0].destroy(); + }); + + s[0].unref(); + }); + } }); - socket.unref(); + + sockets.push([socket, T]); }); process.on('exit', function() { |