From 3b7ece63a4ad7f83c77abca277245c8d1c9487b7 Mon Sep 17 00:00:00 2001 From: Daniel Sims Date: Thu, 1 Dec 2016 10:54:07 -0600 Subject: [PATCH 1/3] test: change var declarations, add mustCall check In this test, I changed the var declarations to be either a let or a const. For some of the callbacks, I added a mustCall check to ensure that the functions have run. --- test/parallel/test-cluster-net-send.js | 27 +++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/test/parallel/test-cluster-net-send.js b/test/parallel/test-cluster-net-send.js index fe536b5f2a43c3..4e1d977ce97d89 100644 --- a/test/parallel/test-cluster-net-send.js +++ b/test/parallel/test-cluster-net-send.js @@ -1,16 +1,16 @@ 'use strict'; -var common = require('../common'); -var assert = require('assert'); -var fork = require('child_process').fork; -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const fork = require('child_process').fork; +const net = require('net'); if (process.argv[2] !== 'child') { console.error('[%d] master', process.pid); - var worker = fork(__filename, ['child']); - var called = false; + const worker = fork(__filename, ['child']); + let called = false; - worker.once('message', function(msg, handle) { + worker.once('message', common.mustCall(function(msg, handle) { assert.equal(msg, 'handle'); assert.ok(handle); worker.send('got'); @@ -23,26 +23,27 @@ if (process.argv[2] !== 'child') { handle.on('end', function() { worker.kill(); }); - }); + })); process.once('exit', function() { + console.log('runs'); assert.ok(called); }); } else { console.error('[%d] worker', process.pid); - var socket; - var cbcalls = 0; + let socket; + let cbcalls = 0; function socketConnected() { if (++cbcalls === 2) process.send('handle', socket); } - var server = net.createServer(function(c) { - process.once('message', function(msg) { + let server = net.createServer(function(c) { + process.once('message', common.mustCall(function(msg) { assert.equal(msg, 'got'); c.end('hello'); - }); + })); socketConnected(); }); server.listen(common.PORT, function() { From 60ba7c87c70217fa47b20aeba5ebff6e242c7c42 Mon Sep 17 00:00:00 2001 From: Daniel Sims Date: Thu, 1 Dec 2016 11:37:50 -0600 Subject: [PATCH 2/3] Removing debug statement --- test/parallel/test-cluster-net-send.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/parallel/test-cluster-net-send.js b/test/parallel/test-cluster-net-send.js index 4e1d977ce97d89..89b18e9025e650 100644 --- a/test/parallel/test-cluster-net-send.js +++ b/test/parallel/test-cluster-net-send.js @@ -26,7 +26,6 @@ if (process.argv[2] !== 'child') { })); process.once('exit', function() { - console.log('runs'); assert.ok(called); }); } else { From f139445eaa3cff21a260aaa67f2bb6d145ce384d Mon Sep 17 00:00:00 2001 From: Daniel Sims Date: Tue, 6 Dec 2016 14:55:42 -0500 Subject: [PATCH 3/3] test: change let declaration, assertions I changed the let to a const declaration, and edited the equal assertions to a strict assertion. --- test/parallel/test-cluster-net-send.js | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-cluster-net-send.js b/test/parallel/test-cluster-net-send.js index 89b18e9025e650..d375920e91b18b 100644 --- a/test/parallel/test-cluster-net-send.js +++ b/test/parallel/test-cluster-net-send.js @@ -11,13 +11,13 @@ if (process.argv[2] !== 'child') { let called = false; worker.once('message', common.mustCall(function(msg, handle) { - assert.equal(msg, 'handle'); + assert.strictEqual(msg, 'handle'); assert.ok(handle); worker.send('got'); handle.on('data', function(data) { called = true; - assert.equal(data.toString(), 'hello'); + assert.strictEqual(data.toString(), 'hello'); }); handle.on('end', function() { @@ -38,13 +38,14 @@ if (process.argv[2] !== 'child') { process.send('handle', socket); } - let server = net.createServer(function(c) { + const server = net.createServer(function(c) { process.once('message', common.mustCall(function(msg) { - assert.equal(msg, 'got'); + assert.strictEqual(msg, 'got'); c.end('hello'); })); socketConnected(); }); + server.listen(common.PORT, function() { socket = net.connect(common.PORT, '127.0.0.1', socketConnected); });