Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 2ab1237

Browse filesBrowse files
TrottMyles Borins
authored andcommitted
test: fix flaky test-net-socket-timeout-unref
Throw immediately on socket timeout rather than checking boolean in exit handler. PR-URL: #6003 Fixes: #5128 Reviewed-By: Myles Borins <myles.borins@gmail.com>
1 parent dd25984 commit 2ab1237
Copy full SHA for 2ab1237

File tree

Expand file treeCollapse file tree

1 file changed

+16
-20
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+16
-20
lines changed
Open diff view settings
Collapse file
+16-20Lines changed: 16 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,39 +1,35 @@
11
'use strict';
2-
var common = require('../common');
3-
var assert = require('assert');
4-
var net = require('net');
52

6-
var server = net.createServer(function(c) {
3+
// Test that unref'ed sockets with timeouts do not prevent exit.
4+
5+
const common = require('../common');
6+
const net = require('net');
7+
8+
const server = net.createServer(function(c) {
79
c.write('hello');
810
c.unref();
911
});
1012
server.listen(common.PORT);
1113
server.unref();
1214

13-
var timedout = false;
1415
var connections = 0;
15-
var sockets = [];
16-
var delays = [8, 5, 3, 6, 2, 4];
16+
const sockets = [];
17+
const delays = [8, 5, 3, 6, 2, 4];
1718

1819
delays.forEach(function(T) {
19-
var socket = net.createConnection(common.PORT, 'localhost');
20-
socket.on('connect', function() {
20+
const socket = net.createConnection(common.PORT, 'localhost');
21+
socket.on('connect', common.mustCall(function() {
2122
if (++connections === delays.length) {
2223
sockets.forEach(function(s) {
23-
s[0].setTimeout(s[1] * 1000, function() {
24-
timedout = true;
25-
s[0].destroy();
24+
s.socket.setTimeout(s.timeout, function() {
25+
s.socket.destroy();
26+
throw new Error('socket timed out unexpectedly');
2627
});
2728

28-
s[0].unref();
29+
s.socket.unref();
2930
});
3031
}
31-
});
32-
33-
sockets.push([socket, T]);
34-
});
32+
}));
3533

36-
process.on('exit', function() {
37-
assert.strictEqual(timedout, false,
38-
'Socket timeout should not hold loop open');
34+
sockets.push({socket: socket, timeout: T * 1000});
3935
});

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.