Browse Source

test: refactor test-cluster-setup-master

- use mustCall instead of counters
- include totalWorkers and settings in the error messages

PR-URL: https://github.com/nodejs/node/pull/16065
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com>
Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
v9.x-staging
Jean-Baptiste Brossard 7 years ago
committed by Joyee Cheung
parent
commit
e8a2438cb6
  1. 35
      test/parallel/test-cluster-setup-master.js

35
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,16 @@ 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 = '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);
});
}

Loading…
Cancel
Save