Skip to content

Commit eb11a70

Browse files
Jean-Baptiste BrossardMylesBorins
Jean-Baptiste Brossard
authored andcommitted
test: refactor test-cluster-setup-master
- 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]>
1 parent 799c6fd commit eb11a70

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed
+17-18
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
'use strict';
2-
require('../common');
2+
const common = require('../common');
33
const assert = require('assert');
44
const cluster = require('cluster');
55

@@ -17,7 +17,7 @@ if (cluster.isWorker) {
1717
};
1818

1919
const totalWorkers = 2;
20-
let onlineWorkers = 0;
20+
let settings;
2121

2222
// Setup master
2323
cluster.setupMaster({
@@ -28,7 +28,7 @@ if (cluster.isWorker) {
2828
cluster.once('setup', function() {
2929
checks.setupEvent = true;
3030

31-
const settings = cluster.settings;
31+
settings = cluster.settings;
3232
if (settings &&
3333
settings.args && settings.args[0] === 'custom argument' &&
3434
settings.silent === true &&
@@ -37,37 +37,36 @@ if (cluster.isWorker) {
3737
}
3838
});
3939

40-
let correctIn = 0;
40+
let correctInput = 0;
4141

42-
cluster.on('online', function lisenter(worker) {
43-
44-
onlineWorkers++;
42+
cluster.on('online', common.mustCall(function listener(worker) {
4543

4644
worker.once('message', function(data) {
47-
correctIn += (data === 'custom argument' ? 1 : 0);
48-
if (correctIn === totalWorkers) {
45+
correctInput += (data === 'custom argument' ? 1 : 0);
46+
if (correctInput === totalWorkers) {
4947
checks.args = true;
5048
}
5149
worker.kill();
5250
});
5351

54-
// All workers are online
55-
if (onlineWorkers === totalWorkers) {
56-
checks.workers = true;
57-
}
58-
});
52+
}, totalWorkers));
5953

6054
// Start all workers
6155
cluster.fork();
6256
cluster.fork();
6357

6458
// Check all values
6559
process.once('exit', function() {
66-
assert.ok(checks.workers, 'Not all workers went online');
67-
assert.ok(checks.args, 'The arguments was noy send to the worker');
60+
const argsMsg = 'Arguments was not send for one or more worker. ' +
61+
`${correctInput} workers receive argument, ` +
62+
`but ${totalWorkers} were expected.`;
63+
assert.ok(checks.args, argsMsg);
64+
6865
assert.ok(checks.setupEvent, 'The setup event was never emitted');
69-
const m = 'The settingsObject do not have correct properties';
70-
assert.ok(checks.settingsObject, m);
66+
67+
const settingObjectMsg = 'The settingsObject do not have correct ' +
68+
`properties : ${JSON.stringify(settings)}`;
69+
assert.ok(checks.settingsObject, settingObjectMsg);
7170
});
7271

7372
}

0 commit comments

Comments
 (0)