Skip to content
Permalink
Browse files

test: fix flaky test-net-socket-timeout

The setTimeout() call is unneeded. If the socket never times out, then
the test will never finish. Because timers can be unreliable on machines
under load, using setTimeout() here effectively creates a race
condition.

PR-URL: nodejs#10172
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
  • Loading branch information
Trott committed Dec 7, 2016
1 parent a0a6ff2 commit 6dd07545ff504c8349a24c936dbf0ecde3c66238
Showing with 14 additions and 15 deletions.
  1. +14 −15 test/parallel/test-net-socket-timeout.js
@@ -1,14 +1,17 @@
'use strict';
var common = require('../common');
var net = require('net');
var assert = require('assert');
const common = require('../common');
const net = require('net');
const assert = require('assert');

// Verify that invalid delays throw
var noop = function() {};
var s = new net.Socket();
var nonNumericDelays = ['100', true, false, undefined, null, '', {}, noop, []];
var badRangeDelays = [-0.001, -1, -Infinity, Infinity, NaN];
var validDelays = [0, 0.001, 1, 1e6];
const noop = function() {};
const s = new net.Socket();
const nonNumericDelays = [
'100', true, false, undefined, null, '', {}, noop, []
];
const badRangeDelays = [-0.001, -1, -Infinity, Infinity, NaN];
const validDelays = [0, 0.001, 1, 1e6];


for (let i = 0; i < nonNumericDelays.length; i++) {
assert.throws(function() {
@@ -28,15 +31,11 @@ for (let i = 0; i < validDelays.length; i++) {
});
}

var server = net.Server();
const server = net.Server();
server.listen(0, common.mustCall(function() {
var socket = net.createConnection(this.address().port);
socket.setTimeout(100, common.mustCall(function() {
const socket = net.createConnection(this.address().port);
socket.setTimeout(1, common.mustCall(function() {
socket.destroy();
server.close();
clearTimeout(timer);
}));
var timer = setTimeout(function() {
process.exit(1);
}, common.platformTimeout(200));
}));

0 comments on commit 6dd0754

Please sign in to comment.
You can’t perform that action at this time.