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-tls-wrap-timeout #7857

Closed
wants to merge 4 commits 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
50 changes: 31 additions & 19 deletions test/parallel/test-tls-wrap-timeout.js
Original file line number Diff line number Diff line change
@@ -1,42 +1,54 @@
'use strict';
var common = require('../common');
var assert = require('assert');
const common = require('../common');

if (!common.hasCrypto) {
common.skip('missing crypto');
return;
}
var tls = require('tls');
const assert = require('assert');
const tls = require('tls');

var net = require('net');
var fs = require('fs');
const net = require('net');
const fs = require('fs');

var options = {
const options = {
key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'),
cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem')
};

var server = tls.createServer(options, function(c) {
setTimeout(function() {
c.write('hello');
setTimeout(function() {
c.destroy();
server.close();
}, 150);
}, 150);
});
const server = tls.createServer(options, common.mustCall((c) => {
setImmediate(() => {
c.write('hello', () => {
setImmediate(() => {
c.destroy();
server.close();
});
});
});
}));

var socket;
var lastIdleStart;

server.listen(0, function() {
var socket = net.connect(this.address().port, function() {
var s = socket.setTimeout(common.platformTimeout(240), function() {
server.listen(0, () => {
socket = net.connect(server.address().port, function() {
const s = socket.setTimeout(Number.MAX_VALUE, function() {
throw new Error('timeout');
});
assert.ok(s instanceof net.Socket);

var tsocket = tls.connect({
assert.notStrictEqual(socket._idleTimeout, -1);
lastIdleStart = socket._idleStart;

const tsocket = tls.connect({
socket: socket,
rejectUnauthorized: false
});
tsocket.resume();
});
});

process.on('exit', () => {
assert.strictEqual(socket._idleTimeout, -1);
assert(lastIdleStart < socket._idleStart);
});