Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Revert "Refactor the message argument pass to the assert module."
This reverts commit ecf7a1778564b5d66b88b19d5653868cb0508286.
  • Loading branch information
Jean-Baptiste Brossard committed Oct 7, 2017
commit 66396bf97fd2e2b6470740ac4ea4fd13a8af3744
33 changes: 18 additions & 15 deletions test/parallel/test-cluster-setup-master.js
Original file line number Diff line number Diff line change
Expand Up @@ -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');

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

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

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

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

}