Skip to content

Commit

Permalink
test: use mustCall in tls-connect-given-socket
Browse files Browse the repository at this point in the history
PR-URL: #12592
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information
vperezma authored and Trott committed May 15, 2017
1 parent b7bc09f commit 72e3dda
Showing 1 changed file with 8 additions and 19 deletions.
27 changes: 8 additions & 19 deletions test/parallel/test-tls-connect-given-socket.js
Expand Up @@ -32,26 +32,20 @@ const tls = require('tls');
const net = require('net'); const net = require('net');
const fs = require('fs'); const fs = require('fs');
const path = require('path'); const path = require('path');

let serverConnected = 0;
let clientConnected = 0;

const options = { const options = {
key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')), key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')),
cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem'))
}; };


const server = tls.createServer(options, (socket) => { const server = tls.createServer(options, common.mustCall((socket) => {
serverConnected++;
socket.end('Hello'); socket.end('Hello');
}).listen(0, () => { }, 2)).listen(0, common.mustCall(() => {
let waiting = 2; let waiting = 2;
function establish(socket) { function establish(socket, calls) {
const client = tls.connect({ const client = tls.connect({
rejectUnauthorized: false, rejectUnauthorized: false,
socket: socket socket: socket
}, () => { }, common.mustCall(() => {
clientConnected++;
let data = ''; let data = '';
client.on('data', common.mustCall((chunk) => { client.on('data', common.mustCall((chunk) => {
data += chunk.toString(); data += chunk.toString();
Expand All @@ -61,7 +55,7 @@ const server = tls.createServer(options, (socket) => {
if (--waiting === 0) if (--waiting === 0)
server.close(); server.close();
})); }));
}); }, calls));
assert(client.readable); assert(client.readable);
assert(client.writable); assert(client.writable);


Expand All @@ -72,14 +66,14 @@ const server = tls.createServer(options, (socket) => {


// Immediate death socket // Immediate death socket
const immediateDeath = net.connect(port); const immediateDeath = net.connect(port);
establish(immediateDeath).destroy(); establish(immediateDeath, 0).destroy();


// Outliving // Outliving
const outlivingTCP = net.connect(port, common.mustCall(() => { const outlivingTCP = net.connect(port, common.mustCall(() => {
outlivingTLS.destroy(); outlivingTLS.destroy();
next(); next();
})); }));
const outlivingTLS = establish(outlivingTCP); const outlivingTLS = establish(outlivingTCP, 0);


function next() { function next() {
// Already connected socket // Already connected socket
Expand All @@ -91,9 +85,4 @@ const server = tls.createServer(options, (socket) => {
const connecting = net.connect(port); const connecting = net.connect(port);
establish(connecting); establish(connecting);
} }
}); }));

process.on('exit', () => {
assert.strictEqual(serverConnected, 2);
assert.strictEqual(clientConnected, 2);
});

0 comments on commit 72e3dda

Please sign in to comment.