From 70aea60155046d359931f34b7cb168ae82e940cd Mon Sep 17 00:00:00 2001 From: vperezma Date: Sat, 22 Apr 2017 11:38:16 -0700 Subject: [PATCH 1/2] test: replaces process exit with mustCall --- test/parallel/test-tls-connect-given-socket.js | 9 +++------ 1 file changed, 3 insertions(+), 6 deletions(-) diff --git a/test/parallel/test-tls-connect-given-socket.js b/test/parallel/test-tls-connect-given-socket.js index 971593b20b50af..43e392c89eadfd 100644 --- a/test/parallel/test-tls-connect-given-socket.js +++ b/test/parallel/test-tls-connect-given-socket.js @@ -33,7 +33,6 @@ const net = require('net'); const fs = require('fs'); const path = require('path'); -let serverConnected = 0; let clientConnected = 0; const options = { @@ -41,10 +40,9 @@ const options = { cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) }; -const server = tls.createServer(options, (socket) => { - serverConnected++; +const server = tls.createServer(options, common.mustCall((socket) => { socket.end('Hello'); -}).listen(0, () => { +}, 2)).listen(0, common.mustCall(() => { let waiting = 2; function establish(socket) { const client = tls.connect({ @@ -91,9 +89,8 @@ const server = tls.createServer(options, (socket) => { const connecting = net.connect(port); establish(connecting); } -}); +})); process.on('exit', () => { - assert.strictEqual(serverConnected, 2); assert.strictEqual(clientConnected, 2); }); From 5080f065893c3a6ef8ef53746ffe126bd2f145cd Mon Sep 17 00:00:00 2001 From: vperezma Date: Sat, 22 Apr 2017 11:46:46 -0700 Subject: [PATCH 2/2] test: remove process on add must call --- test/parallel/test-tls-connect-given-socket.js | 18 +++++------------- 1 file changed, 5 insertions(+), 13 deletions(-) diff --git a/test/parallel/test-tls-connect-given-socket.js b/test/parallel/test-tls-connect-given-socket.js index 43e392c89eadfd..08553916194116 100644 --- a/test/parallel/test-tls-connect-given-socket.js +++ b/test/parallel/test-tls-connect-given-socket.js @@ -32,9 +32,6 @@ const tls = require('tls'); const net = require('net'); const fs = require('fs'); const path = require('path'); - -let clientConnected = 0; - const options = { key: fs.readFileSync(path.join(common.fixturesDir, 'test_key.pem')), cert: fs.readFileSync(path.join(common.fixturesDir, 'test_cert.pem')) @@ -44,12 +41,11 @@ const server = tls.createServer(options, common.mustCall((socket) => { socket.end('Hello'); }, 2)).listen(0, common.mustCall(() => { let waiting = 2; - function establish(socket) { + function establish(socket, calls) { const client = tls.connect({ rejectUnauthorized: false, socket: socket - }, () => { - clientConnected++; + }, common.mustCall(() => { let data = ''; client.on('data', common.mustCall((chunk) => { data += chunk.toString(); @@ -59,7 +55,7 @@ const server = tls.createServer(options, common.mustCall((socket) => { if (--waiting === 0) server.close(); })); - }); + }, calls)); assert(client.readable); assert(client.writable); @@ -70,14 +66,14 @@ const server = tls.createServer(options, common.mustCall((socket) => { // Immediate death socket const immediateDeath = net.connect(port); - establish(immediateDeath).destroy(); + establish(immediateDeath, 0).destroy(); // Outliving const outlivingTCP = net.connect(port, common.mustCall(() => { outlivingTLS.destroy(); next(); })); - const outlivingTLS = establish(outlivingTCP); + const outlivingTLS = establish(outlivingTCP, 0); function next() { // Already connected socket @@ -90,7 +86,3 @@ const server = tls.createServer(options, common.mustCall((socket) => { establish(connecting); } })); - -process.on('exit', () => { - assert.strictEqual(clientConnected, 2); -});