Browse Source

test: fix flaky test-tls-wrap-timeout

Competing timers were causing a race condition and thus the test was
flaky. Instead, we check an object property on process exit.

Fixes: https://github.com/nodejs/node/issues/7650
Backport-PR-URL: https://github.com/nodejs/node/pull/12567
PR-URL: https://github.com/nodejs/node/pull/7857
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Fedor Indutny <fedor.indutny@gmail.com>
Reviewed-By: jasnell - James M Snell <jasnell@gmail.com>
v4.x
Rich Trott 9 years ago
committed by Myles Borins
parent
commit
6040efd7dc
No known key found for this signature in database GPG Key ID: 933B01F40B5CA946
  1. 44
      test/parallel/test-tls-wrap-timeout.js

44
test/parallel/test-tls-wrap-timeout.js

@ -1,42 +1,54 @@
'use strict'; 'use strict';
var common = require('../common'); const common = require('../common');
var assert = require('assert');
if (!common.hasCrypto) { if (!common.hasCrypto) {
common.skip('missing crypto'); common.skip('missing crypto');
return; return;
} }
var tls = require('tls'); const assert = require('assert');
const tls = require('tls');
var net = require('net'); const net = require('net');
var fs = require('fs'); const fs = require('fs');
var options = { const options = {
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem') cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
}; };
var server = tls.createServer(options, function(c) { const server = tls.createServer(options, common.mustCall((c) => {
setTimeout(function() { setImmediate(() => {
c.write('hello'); c.write('hello', () => {
setTimeout(function() { setImmediate(() => {
c.destroy(); c.destroy();
server.close(); server.close();
}, 150);
}, 150);
}); });
});
});
}));
var socket;
var lastIdleStart;
server.listen(0, function() { server.listen(0, () => {
var socket = net.connect(this.address().port, function() { socket = net.connect(server.address().port, function() {
var s = socket.setTimeout(common.platformTimeout(240), function() { const s = socket.setTimeout(Number.MAX_VALUE, function() {
throw new Error('timeout'); throw new Error('timeout');
}); });
assert.ok(s instanceof net.Socket); assert.ok(s instanceof net.Socket);
var tsocket = tls.connect({ assert.notStrictEqual(socket._idleTimeout, -1);
lastIdleStart = socket._idleStart;
const tsocket = tls.connect({
socket: socket, socket: socket,
rejectUnauthorized: false rejectUnauthorized: false
}); });
tsocket.resume(); tsocket.resume();
}); });
}); });
process.on('exit', () => {
assert.strictEqual(socket._idleTimeout, -1);
assert(lastIdleStart < socket._idleStart);
});

Loading…
Cancel
Save