Skip to content

Commit

Permalink
test: refactor test-cluster-setup-master
Browse files Browse the repository at this point in the history
- use mustCall instead of counters
- include totalWorkers and settings in the error messages

PR-URL: #16065
Reviewed-By: Ruben Bridgewater <[email protected]>
Reviewed-By: Joyee Cheung <[email protected]>
Reviewed-By: Yuta Hiroto <[email protected]>
  • Loading branch information
Jean-Baptiste Brossard authored and MylesBorins committed Nov 28, 2017
1 parent 799c6fd commit eb11a70
Showing 1 changed file with 17 additions and 18 deletions.
35 changes: 17 additions & 18 deletions test/parallel/test-cluster-setup-master.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
'use strict';
require('../common');
const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');

Expand All @@ -17,7 +17,7 @@ if (cluster.isWorker) {
};

const totalWorkers = 2;
let onlineWorkers = 0;
let settings;

// Setup master
cluster.setupMaster({
Expand All @@ -28,7 +28,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 &&
Expand All @@ -37,37 +37,36 @@ 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();
cluster.fork();

// 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 = '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 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);
});

}

0 comments on commit eb11a70

Please sign in to comment.