Browse Source

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>
v4.x
Santiago Gimeno 9 years ago
committed by Myles Borins
parent
commit
962c0e4e24
  1. 21
      test/parallel/test-net-socket-timeout-unref.js

21
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());
socket.on('connect', function() {
if (++connections === delays.length) {
sockets.forEach(function(s) {
s[0].setTimeout(s[1] * 1000, function() {
timedout = true;
socket.destroy();
s[0].destroy();
});
socket.unref();
s[0].unref();
});
}
});
sockets.push([socket, T]);
});
process.on('exit', function() {

Loading…
Cancel
Save