Skip to content

Commit 3f9b0a9

Browse files
Jean-Baptiste Brossardtargos
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 <ruben@bridgewater.de> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
1 parent 4ecc288 commit 3f9b0a9

File tree

1 file changed

+17
-18
lines changed

1 file changed

+17
-18
lines changed

test/parallel/test-cluster-setup-master.js

+17-18
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
require('../common');
23+
const common = require('../common');
2424
const assert = require('assert');
2525
const cluster = require('cluster');
2626

@@ -38,7 +38,7 @@ if (cluster.isWorker) {
3838
};
3939

4040
const totalWorkers = 2;
41-
let onlineWorkers = 0;
41+
let settings;
4242

4343
// Setup master
4444
cluster.setupMaster({
@@ -49,7 +49,7 @@ if (cluster.isWorker) {
4949
cluster.once('setup', function() {
5050
checks.setupEvent = true;
5151

52-
const settings = cluster.settings;
52+
settings = cluster.settings;
5353
if (settings &&
5454
settings.args && settings.args[0] === 'custom argument' &&
5555
settings.silent === true &&
@@ -58,37 +58,36 @@ if (cluster.isWorker) {
5858
}
5959
});
6060

61-
let correctIn = 0;
61+
let correctInput = 0;
6262

63-
cluster.on('online', function lisenter(worker) {
64-
65-
onlineWorkers++;
63+
cluster.on('online', common.mustCall(function listener(worker) {
6664

6765
worker.once('message', function(data) {
68-
correctIn += (data === 'custom argument' ? 1 : 0);
69-
if (correctIn === totalWorkers) {
66+
correctInput += (data === 'custom argument' ? 1 : 0);
67+
if (correctInput === totalWorkers) {
7068
checks.args = true;
7169
}
7270
worker.kill();
7371
});
7472

75-
// All workers are online
76-
if (onlineWorkers === totalWorkers) {
77-
checks.workers = true;
78-
}
79-
});
73+
}, totalWorkers));
8074

8175
// Start all workers
8276
cluster.fork();
8377
cluster.fork();
8478

8579
// Check all values
8680
process.once('exit', function() {
87-
assert.ok(checks.workers, 'Not all workers went online');
88-
assert.ok(checks.args, 'The arguments was noy send to the worker');
81+
const argsMsg = 'Arguments was not send for one or more worker. ' +
82+
`${correctInput} workers receive argument, ` +
83+
`but ${totalWorkers} were expected.`;
84+
assert.ok(checks.args, argsMsg);
85+
8986
assert.ok(checks.setupEvent, 'The setup event was never emitted');
90-
const m = 'The settingsObject do not have correct properties';
91-
assert.ok(checks.settingsObject, m);
87+
88+
const settingObjectMsg = 'The settingsObject do not have correct ' +
89+
`properties : ${JSON.stringify(settings)}`;
90+
assert.ok(checks.settingsObject, settingObjectMsg);
9291
});
9392

9493
}

0 commit comments

Comments
 (0)