From bbe618d3e251e29a896635c6b96a75f622ac2395 Mon Sep 17 00:00:00 2001 From: Amar Zavery Date: Thu, 1 Dec 2016 11:55:13 -0600 Subject: [PATCH] test: refactor test-cluster-send-handle-twice.js - `var` --> `const` as applicable - `assert.equal` --> `assert.strictEqual` - `assert(false, ..)` --> `common.fail()` - `common.mustCall` for functions that need to be called exactly once - modified an `assert(!signal, 'Worker exited by a signal');` call to `assert.strictEqual(signal, null);` call as that made more sense PR-URL: https://github.com/nodejs/node/pull/10049 Reviewed-By: Rich Trott Reviewed-By: Colin Ihrig --- .../test-cluster-send-handle-twice.js | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/test/parallel/test-cluster-send-handle-twice.js b/test/parallel/test-cluster-send-handle-twice.js index 172a5563f306f5..f4d1bd8e0cc137 100644 --- a/test/parallel/test-cluster-send-handle-twice.js +++ b/test/parallel/test-cluster-send-handle-twice.js @@ -1,36 +1,36 @@ 'use strict'; // Testing to send an handle twice to the parent process. -var common = require('../common'); -var assert = require('assert'); -var cluster = require('cluster'); -var net = require('net'); +const common = require('../common'); +const assert = require('assert'); +const cluster = require('cluster'); +const net = require('net'); -var workers = { +const workers = { toStart: 1 }; if (cluster.isMaster) { - for (var i = 0; i < workers.toStart; ++i) { - var worker = cluster.fork(); - worker.on('exit', function(code, signal) { + for (let i = 0; i < workers.toStart; ++i) { + const worker = cluster.fork(); + worker.on('exit', common.mustCall(function(code, signal) { assert.strictEqual(code, 0, 'Worker exited with an error code'); - assert(!signal, 'Worker exited by a signal'); - }); + assert.strictEqual(signal, null, 'Worker exited by a signal'); + })); } } else { - var server = net.createServer(function(socket) { + const server = net.createServer(function(socket) { process.send('send-handle-1', socket); process.send('send-handle-2', socket); }); server.listen(common.PORT, function() { - var client = net.connect({ host: 'localhost', port: common.PORT }); - client.on('close', function() { cluster.worker.disconnect(); }); + const client = net.connect({ host: 'localhost', port: common.PORT }); + client.on('close', common.mustCall(() => { cluster.worker.disconnect(); })); setTimeout(function() { client.end(); }, 50); }).on('error', function(e) { console.error(e); - assert(false, 'server.listen failed'); + common.fail('server.listen failed'); cluster.worker.disconnect(); }); }