From 694d8f6b3fc8e7b4067dc16c3c71e6990f87e6c6 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Brossard Date: Fri, 6 Oct 2017 12:30:14 -0700 Subject: [PATCH 1/5] Refactor the message argument pass to the assert module. --- test/parallel/test-cluster-setup-master.js | 33 ++++++++++------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/test/parallel/test-cluster-setup-master.js b/test/parallel/test-cluster-setup-master.js index 3252c5ce07f1e1..8f0dbab3073a87 100644 --- a/test/parallel/test-cluster-setup-master.js +++ b/test/parallel/test-cluster-setup-master.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const cluster = require('cluster'); @@ -38,7 +38,7 @@ if (cluster.isWorker) { }; const totalWorkers = 2; - let onlineWorkers = 0; + let settings; // Setup master cluster.setupMaster({ @@ -49,7 +49,7 @@ if (cluster.isWorker) { cluster.once('setup', function() { checks.setupEvent = true; - const settings = cluster.settings; + settings = cluster.settings; if (settings && settings.args && settings.args[0] === 'custom argument' && settings.silent === true && @@ -58,25 +58,19 @@ if (cluster.isWorker) { } }); - let correctIn = 0; + let correctInput = 0; - cluster.on('online', function lisenter(worker) { - - onlineWorkers++; + cluster.on('online', common.mustCall(function listener(worker) { worker.once('message', function(data) { - correctIn += (data === 'custom argument' ? 1 : 0); - if (correctIn === totalWorkers) { + correctInput += (data === 'custom argument' ? 1 : 0); + if (correctInput === totalWorkers) { checks.args = true; } worker.kill(); }); - // All workers are online - if (onlineWorkers === totalWorkers) { - checks.workers = true; - } - }); + }, totalWorkers)); // Start all workers cluster.fork(); @@ -84,11 +78,14 @@ if (cluster.isWorker) { // Check all values process.once('exit', function() { - assert.ok(checks.workers, 'Not all workers went online'); - assert.ok(checks.args, 'The arguments was noy send to the worker'); + const argsMsg = `The arguments was not send for one or more worker. + There was ${correctInput} worker that receive argument, + ${totalWorkers} were expected`; + assert.ok(checks.args, argsMsg); assert.ok(checks.setupEvent, 'The setup event was never emitted'); - const m = 'The settingsObject do not have correct properties'; - assert.ok(checks.settingsObject, m); + const settingObjectMsg = `The settingsObject do not have correct properties : + ${JSON.stringify(settings)}`; + assert.ok(checks.settingsObject, settingObjectMsg); }); } From 66396bf97fd2e2b6470740ac4ea4fd13a8af3744 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Brossard Date: Fri, 6 Oct 2017 12:31:17 -0700 Subject: [PATCH 2/5] Revert "Refactor the message argument pass to the assert module." This reverts commit ecf7a1778564b5d66b88b19d5653868cb0508286. --- test/parallel/test-cluster-setup-master.js | 33 ++++++++++++---------- 1 file changed, 18 insertions(+), 15 deletions(-) diff --git a/test/parallel/test-cluster-setup-master.js b/test/parallel/test-cluster-setup-master.js index 8f0dbab3073a87..3252c5ce07f1e1 100644 --- a/test/parallel/test-cluster-setup-master.js +++ b/test/parallel/test-cluster-setup-master.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -const common = require('../common'); +require('../common'); const assert = require('assert'); const cluster = require('cluster'); @@ -38,7 +38,7 @@ if (cluster.isWorker) { }; const totalWorkers = 2; - let settings; + let onlineWorkers = 0; // Setup master cluster.setupMaster({ @@ -49,7 +49,7 @@ if (cluster.isWorker) { cluster.once('setup', function() { checks.setupEvent = true; - settings = cluster.settings; + const settings = cluster.settings; if (settings && settings.args && settings.args[0] === 'custom argument' && settings.silent === true && @@ -58,19 +58,25 @@ if (cluster.isWorker) { } }); - let correctInput = 0; + let correctIn = 0; - cluster.on('online', common.mustCall(function listener(worker) { + cluster.on('online', function lisenter(worker) { + + onlineWorkers++; worker.once('message', function(data) { - correctInput += (data === 'custom argument' ? 1 : 0); - if (correctInput === totalWorkers) { + correctIn += (data === 'custom argument' ? 1 : 0); + if (correctIn === totalWorkers) { checks.args = true; } worker.kill(); }); - }, totalWorkers)); + // All workers are online + if (onlineWorkers === totalWorkers) { + checks.workers = true; + } + }); // Start all workers cluster.fork(); @@ -78,14 +84,11 @@ if (cluster.isWorker) { // Check all values process.once('exit', function() { - const argsMsg = `The arguments was not send for one or more worker. - There was ${correctInput} worker that receive argument, - ${totalWorkers} were expected`; - assert.ok(checks.args, argsMsg); + assert.ok(checks.workers, 'Not all workers went online'); + assert.ok(checks.args, 'The arguments was noy send to the worker'); assert.ok(checks.setupEvent, 'The setup event was never emitted'); - const settingObjectMsg = `The settingsObject do not have correct properties : - ${JSON.stringify(settings)}`; - assert.ok(checks.settingsObject, settingObjectMsg); + const m = 'The settingsObject do not have correct properties'; + assert.ok(checks.settingsObject, m); }); } From aa354e1f2e57f44807a0ac6d9f4cf857b2bd36ea Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Brossard Date: Fri, 6 Oct 2017 12:32:25 -0700 Subject: [PATCH 3/5] Refactor the message argument pass to the assert module. - The assert "assert.ok(checks.workers, 'Not all workers went online');" was remove, instead, mustCall was add around the callback that is called after a worker get online. So you don't have to do something like : "onlineWorker ++ , if onlineWorker == totalWorker". - The assert that make sure if all the worker got their arguments got his message refactor so that it include the number of worker that got argument vs the expected number of argument. - The assert that check if the setting object have his properties fill got his message refactor, it now print the content of the setting object. --- test/parallel/test-cluster-setup-master.js | 33 ++++++++++------------ 1 file changed, 15 insertions(+), 18 deletions(-) diff --git a/test/parallel/test-cluster-setup-master.js b/test/parallel/test-cluster-setup-master.js index 3252c5ce07f1e1..8f0dbab3073a87 100644 --- a/test/parallel/test-cluster-setup-master.js +++ b/test/parallel/test-cluster-setup-master.js @@ -20,7 +20,7 @@ // USE OR OTHER DEALINGS IN THE SOFTWARE. 'use strict'; -require('../common'); +const common = require('../common'); const assert = require('assert'); const cluster = require('cluster'); @@ -38,7 +38,7 @@ if (cluster.isWorker) { }; const totalWorkers = 2; - let onlineWorkers = 0; + let settings; // Setup master cluster.setupMaster({ @@ -49,7 +49,7 @@ if (cluster.isWorker) { cluster.once('setup', function() { checks.setupEvent = true; - const settings = cluster.settings; + settings = cluster.settings; if (settings && settings.args && settings.args[0] === 'custom argument' && settings.silent === true && @@ -58,25 +58,19 @@ if (cluster.isWorker) { } }); - let correctIn = 0; + let correctInput = 0; - cluster.on('online', function lisenter(worker) { - - onlineWorkers++; + cluster.on('online', common.mustCall(function listener(worker) { worker.once('message', function(data) { - correctIn += (data === 'custom argument' ? 1 : 0); - if (correctIn === totalWorkers) { + correctInput += (data === 'custom argument' ? 1 : 0); + if (correctInput === totalWorkers) { checks.args = true; } worker.kill(); }); - // All workers are online - if (onlineWorkers === totalWorkers) { - checks.workers = true; - } - }); + }, totalWorkers)); // Start all workers cluster.fork(); @@ -84,11 +78,14 @@ if (cluster.isWorker) { // Check all values process.once('exit', function() { - assert.ok(checks.workers, 'Not all workers went online'); - assert.ok(checks.args, 'The arguments was noy send to the worker'); + const argsMsg = `The arguments was not send for one or more worker. + There was ${correctInput} worker that receive argument, + ${totalWorkers} were expected`; + assert.ok(checks.args, argsMsg); assert.ok(checks.setupEvent, 'The setup event was never emitted'); - const m = 'The settingsObject do not have correct properties'; - assert.ok(checks.settingsObject, m); + const settingObjectMsg = `The settingsObject do not have correct properties : + ${JSON.stringify(settings)}`; + assert.ok(checks.settingsObject, settingObjectMsg); }); } From e769f549699c71b6ea735d28a1bbeb803e0476d4 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Brossard Date: Sat, 7 Oct 2017 10:23:25 -0700 Subject: [PATCH 4/5] Make message smaller to fit on less than 80 character long. --- test/parallel/test-cluster-setup-master.js | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/test/parallel/test-cluster-setup-master.js b/test/parallel/test-cluster-setup-master.js index 8f0dbab3073a87..f0a73af4e5a638 100644 --- a/test/parallel/test-cluster-setup-master.js +++ b/test/parallel/test-cluster-setup-master.js @@ -79,12 +79,12 @@ if (cluster.isWorker) { // Check all values process.once('exit', function() { const argsMsg = `The arguments was not send for one or more worker. - There was ${correctInput} worker that receive argument, - ${totalWorkers} were expected`; + There was ${correctInput} worker that receive + argument, ${totalWorkers} were expected`; assert.ok(checks.args, argsMsg); assert.ok(checks.setupEvent, 'The setup event was never emitted'); - const settingObjectMsg = `The settingsObject do not have correct properties : - ${JSON.stringify(settings)}`; + const settingObjectMsg = `The settingsObject do not have correct + properties : ${JSON.stringify(settings)}`; assert.ok(checks.settingsObject, settingObjectMsg); }); From b31652dd9c6146794872da2d0e879f2a18b62700 Mon Sep 17 00:00:00 2001 From: Jean-Baptiste Brossard Date: Sun, 8 Oct 2017 15:40:02 -0400 Subject: [PATCH 5/5] Change indentation for concatenation for assert message --- test/parallel/test-cluster-setup-master.js | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/test/parallel/test-cluster-setup-master.js b/test/parallel/test-cluster-setup-master.js index f0a73af4e5a638..619a8439904d92 100644 --- a/test/parallel/test-cluster-setup-master.js +++ b/test/parallel/test-cluster-setup-master.js @@ -78,13 +78,15 @@ if (cluster.isWorker) { // Check all values process.once('exit', function() { - const argsMsg = `The arguments was not send for one or more worker. - There was ${correctInput} worker that receive - argument, ${totalWorkers} were expected`; + const argsMsg = 'Arguments was not send for one or more worker. ' + + `${correctInput} workers receive argument, ` + + `but ${totalWorkers} were expected.`; assert.ok(checks.args, argsMsg); + assert.ok(checks.setupEvent, 'The setup event was never emitted'); - const settingObjectMsg = `The settingsObject do not have correct - properties : ${JSON.stringify(settings)}`; + + const settingObjectMsg = 'The settingsObject do not have correct ' + + `properties : ${JSON.stringify(settings)}`; assert.ok(checks.settingsObject, settingObjectMsg); });