Skip to content
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
  • Loading branch information
santigimeno committed Feb 3, 2016
commit 3e674291d0e64954aeb3508fc690ad28fec47709
23 changes: 17 additions & 6 deletions test/parallel/test-net-socket-timeout-unref.js
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down