Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix flaky test-net-socket-timeout-unref #6003

Closed
wants to merge 1 commit into from
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
36 changes: 16 additions & 20 deletions test/parallel/test-net-socket-timeout-unref.js
Original file line number Diff line number Diff line change
@@ -1,39 +1,35 @@
'use strict';
var common = require('../common');
var assert = require('assert');
var net = require('net');

var server = net.createServer(function(c) {
// Test that unref'ed sockets with timeouts do not prevent exit.

const common = require('../common');
const net = require('net');

const server = net.createServer(function(c) {
c.write('hello');
c.unref();
});
server.listen(common.PORT);
server.unref();

var timedout = false;
var connections = 0;
var sockets = [];
var delays = [8, 5, 3, 6, 2, 4];
const sockets = [];
const delays = [8, 5, 3, 6, 2, 4];

delays.forEach(function(T) {
var socket = net.createConnection(common.PORT, 'localhost');
socket.on('connect', function() {
const socket = net.createConnection(common.PORT, 'localhost');
socket.on('connect', common.mustCall(function() {
if (++connections === delays.length) {
sockets.forEach(function(s) {
s[0].setTimeout(s[1] * 1000, function() {
timedout = true;
s[0].destroy();
s.socket.setTimeout(s.timeout, function() {
s.socket.destroy();
throw new Error('socket timed out unexpectedly');
});

s[0].unref();
s.socket.unref();
});
}
});

sockets.push([socket, T]);
});
}));

process.on('exit', function() {
assert.strictEqual(timedout, false,
'Socket timeout should not hold loop open');
sockets.push({socket: socket, timeout: T * 1000});
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

should this timout be platform specific?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is a socket timeout and not a timer, so I'm inclined to not make it platform dependent if it doesn't need to be.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ahhh... /me leaves and reads more about socket time outs

});