Skip to content

Commit 09917c9

Browse files
santigimenorvagg
authored andcommitted
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: #4772 Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent dde1603 commit 09917c9

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

test/parallel/test-net-socket-timeout-unref.js

+17-6
Original file line numberDiff line numberDiff line change
@@ -11,15 +11,26 @@ server.listen(common.PORT);
1111
server.unref();
1212

1313
var timedout = false;
14+
var connections = 0;
15+
var sockets = [];
16+
var delays = [8, 5, 3, 6, 2, 4];
1417

15-
[8, 5, 3, 6, 2, 4].forEach(function(T) {
18+
delays.forEach(function(T) {
1619
var socket = net.createConnection(common.PORT, 'localhost');
17-
socket.setTimeout(T * 1000, function() {
18-
console.log(process._getActiveHandles());
19-
timedout = true;
20-
socket.destroy();
20+
socket.on('connect', function() {
21+
if (++connections === delays.length) {
22+
sockets.forEach(function(s) {
23+
s[0].setTimeout(s[1] * 1000, function() {
24+
timedout = true;
25+
s[0].destroy();
26+
});
27+
28+
s[0].unref();
29+
});
30+
}
2131
});
22-
socket.unref();
32+
33+
sockets.push([socket, T]);
2334
});
2435

2536
process.on('exit', function() {

0 commit comments

Comments
 (0)