From 52ad3f51fd6205f0963ca3b2d6ea5e12ba613a1c Mon Sep 17 00:00:00 2001 From: Yojan Shrestha Date: Thu, 1 Dec 2016 11:05:59 -0600 Subject: [PATCH 1/3] test: refactors variable and assertions - changes var to const/let - changes assert.equal to assert.strictEqual **Note: `process.on('exit')` wasn't able to change the handler to `common.mustCall` because `common.mustCall` actually uses `process.on('exit')` internally** --- test/parallel/test-tls-ticket.js | 48 ++++++++++++++++---------------- 1 file changed, 24 insertions(+), 24 deletions(-) diff --git a/test/parallel/test-tls-ticket.js b/test/parallel/test-tls-ticket.js index 8457b15e0cd325..61edd708e7c8ac 100644 --- a/test/parallel/test-tls-ticket.js +++ b/test/parallel/test-tls-ticket.js @@ -1,29 +1,29 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var fs = require('fs'); -var net = require('net'); -var crypto = require('crypto'); +const fs = require('fs'); +const net = require('net'); +const crypto = require('crypto'); -var keys = crypto.randomBytes(48); -var serverLog = []; -var ticketLog = []; +const keys = crypto.randomBytes(48); +const serverLog = []; +const ticketLog = []; -var serverCount = 0; +let serverCount = 0; function createServer() { - var id = serverCount++; + const id = serverCount++; - var counter = 0; - var previousKey = null; + let counter = 0; + let previousKey = null; - var server = tls.createServer({ + const server = tls.createServer({ key: fs.readFileSync(common.fixturesDir + '/keys/agent1-key.pem'), cert: fs.readFileSync(common.fixturesDir + '/keys/agent1-cert.pem'), ticketKeys: keys @@ -49,13 +49,13 @@ function createServer() { return server; } -var naturalServers = [ createServer(), createServer(), createServer() ]; +const naturalServers = [ createServer(), createServer(), createServer() ]; // 3x servers -var servers = naturalServers.concat(naturalServers).concat(naturalServers); +const servers = naturalServers.concat(naturalServers).concat(naturalServers); // Create one TCP server and balance sockets to multiple TLS server instances -var shared = net.createServer(function(c) { +const shared = net.createServer(function(c) { servers.shift().emit('connection', c); }).listen(0, function() { start(function() { @@ -64,11 +64,11 @@ var shared = net.createServer(function(c) { }); function start(callback) { - var sess = null; - var left = servers.length; + let sess = null; + let left = servers.length; function connect() { - var s = tls.connect(shared.address().port, { + const s = tls.connect(shared.address().port, { session: sess, rejectUnauthorized: false }, function() { @@ -87,15 +87,15 @@ function start(callback) { } process.on('exit', function() { - assert.equal(ticketLog.length, serverLog.length); - for (var i = 0; i < naturalServers.length - 1; i++) { + assert.strictEqual(ticketLog.length, serverLog.length); + for (let i = 0; i < naturalServers.length - 1; i++) { assert.notEqual(serverLog[i], serverLog[i + 1]); - assert.equal(ticketLog[i], ticketLog[i + 1]); + assert.strictEqual(ticketLog[i], ticketLog[i + 1]); // 2nd connection should have different ticket assert.notEqual(ticketLog[i], ticketLog[i + naturalServers.length]); // 3rd connection should have the same ticket - assert.equal(ticketLog[i], ticketLog[i + naturalServers.length * 2]); + assert.strictEqual(ticketLog[i], ticketLog[i + naturalServers.length * 2]); } }); From 219ca570fa82a728e73d5ead0fc47f83c5071695 Mon Sep 17 00:00:00 2001 From: Yojan Shrestha Date: Thu, 1 Dec 2016 11:14:14 -0600 Subject: [PATCH 2/3] test: refactors variable and assertions - changes var to const/let - change assert.equal to assert.strictEqual **Note: `process.on('exit')` wasn't able to change the handler to `common.mustCall` because `common.mustCall` actually uses `process.on('exit')` internally** --- test/parallel/test-tls-ticket-cluster.js | 46 ++++++++++++------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/test/parallel/test-tls-ticket-cluster.js b/test/parallel/test-tls-ticket-cluster.js index 4d1667a7adcab2..fa630f4ec251bd 100644 --- a/test/parallel/test-tls-ticket-cluster.js +++ b/test/parallel/test-tls-ticket-cluster.js @@ -1,29 +1,29 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); +const common = require('../common'); +const assert = require('assert'); if (!common.hasCrypto) { common.skip('missing crypto'); return; } -var tls = require('tls'); +const tls = require('tls'); -var cluster = require('cluster'); -var fs = require('fs'); -var join = require('path').join; +const cluster = require('cluster'); +const fs = require('fs'); +const join = require('path').join; -var workerCount = 4; -var expectedReqCount = 16; +const workerCount = 4; +const expectedReqCount = 16; if (cluster.isMaster) { - var reusedCount = 0; - var reqCount = 0; - var lastSession = null; - var shootOnce = false; + let reusedCount = 0; + let reqCount = 0; + let lastSession = null; + let shootOnce = false; function shoot() { console.error('[master] connecting'); - var c = tls.connect(common.PORT, { + const c = tls.connect(common.PORT, { session: lastSession, rejectUnauthorized: false }, function() { @@ -41,7 +41,7 @@ if (cluster.isMaster) { } function fork() { - var worker = cluster.fork(); + const worker = cluster.fork(); worker.on('message', function(msg) { console.error('[master] got %j', msg); if (msg === 'reused') { @@ -56,27 +56,27 @@ if (cluster.isMaster) { console.error('[master] worker died'); }); } - for (var i = 0; i < workerCount; i++) { + for (let i = 0; i < workerCount; i++) { fork(); } process.on('exit', function() { - assert.equal(reqCount, expectedReqCount); - assert.equal(reusedCount + 1, reqCount); + assert.strictEqual(reqCount, expectedReqCount); + assert.strictEqual(reusedCount + 1, reqCount); }); return; } -var keyFile = join(common.fixturesDir, 'agent.key'); -var certFile = join(common.fixturesDir, 'agent.crt'); -var key = fs.readFileSync(keyFile); -var cert = fs.readFileSync(certFile); -var options = { +const keyFile = join(common.fixturesDir, 'agent.key'); +const certFile = join(common.fixturesDir, 'agent.crt'); +const key = fs.readFileSync(keyFile); +const cert = fs.readFileSync(certFile); +const options = { key: key, cert: cert }; -var server = tls.createServer(options, function(c) { +const server = tls.createServer(options, function(c) { if (c.isSessionReused()) { process.send('reused'); } else { From f4c05a9f8bd542ddb50ab9bf5d6ca28064bc1fce Mon Sep 17 00:00:00 2001 From: Yojan Shrestha Date: Tue, 6 Dec 2016 22:34:00 -0600 Subject: [PATCH 3/3] test: refactors assertion - changes `notEqual` to `notStrictEqual` --- test/parallel/test-tls-ticket.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-tls-ticket.js b/test/parallel/test-tls-ticket.js index 61edd708e7c8ac..0fa0c057f3e573 100644 --- a/test/parallel/test-tls-ticket.js +++ b/test/parallel/test-tls-ticket.js @@ -89,11 +89,11 @@ function start(callback) { process.on('exit', function() { assert.strictEqual(ticketLog.length, serverLog.length); for (let i = 0; i < naturalServers.length - 1; i++) { - assert.notEqual(serverLog[i], serverLog[i + 1]); + assert.notStrictEqual(serverLog[i], serverLog[i + 1]); assert.strictEqual(ticketLog[i], ticketLog[i + 1]); // 2nd connection should have different ticket - assert.notEqual(ticketLog[i], ticketLog[i + naturalServers.length]); + assert.notStrictEqual(ticketLog[i], ticketLog[i + naturalServers.length]); // 3rd connection should have the same ticket assert.strictEqual(ticketLog[i], ticketLog[i + naturalServers.length * 2]);