Skip to content

Commit

Permalink
test: refactor parallel/test-tls-async-cb-after-socket-end
Browse files Browse the repository at this point in the history
PR-URL: #18985
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Richard Lau <riclau@uk.ibm.com>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
  • Loading branch information
juggernaut451 authored and targos committed Apr 12, 2018
1 parent 6613169 commit 4eef82e
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions test/parallel/test-tls-async-cb-after-socket-end.js
Original file line number Diff line number Diff line change
@@ -1,66 +1,65 @@
'use strict';

const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const fixtures = require('../common/fixtures');
const SSL_OP_NO_TICKET = require('crypto').constants.SSL_OP_NO_TICKET;
const tls = require('tls');

// Check tls async callback after socket ends

const options = {
secureOptions: SSL_OP_NO_TICKET,
key: fixtures.readSync('test_key.pem'),
cert: fixtures.readSync('test_cert.pem')
};

const server = tls.createServer(options, function(c) {
});
const server = tls.createServer(options, common.mustCall());

let sessionCb = null;
let client = null;

server.on('newSession', function(key, session, done) {
server.on('newSession', common.mustCall((key, session, done) => {
done();
});
}));

server.on('resumeSession', function(id, cb) {
server.on('resumeSession', common.mustCall((id, cb) => {
sessionCb = cb;

next();
});
}));

server.listen(0, function() {
server.listen(0, common.mustCall(() => {
const clientOpts = {
port: this.address().port,
port: server.address().port,
rejectUnauthorized: false,
session: false
};

const s1 = tls.connect(clientOpts, function() {
const s1 = tls.connect(clientOpts, common.mustCall(() => {
clientOpts.session = s1.getSession();
console.log('1st secure');

s1.destroy();
const s2 = tls.connect(clientOpts, function(s) {
const s2 = tls.connect(clientOpts, (s) => {
console.log('2nd secure');

s2.destroy();
}).on('connect', function() {
}).on('connect', common.mustCall(() => {
console.log('2nd connected');
client = s2;

next();
});
});
});
}));
}));
}));

function next() {
if (!client || !sessionCb)
return;

client.destroy();
setTimeout(function() {
setTimeout(common.mustCall(() => {
sessionCb();
server.close();
}, 100);
}), 100);
}

0 comments on commit 4eef82e

Please sign in to comment.