Skip to content

Commit cec5e36

Browse files
imyllerMyles Borins
authored and
Myles Borins
committed
test: fix test-cluster-worker-init.js flakyness
Update test to match current test guidelines and use common.mustCall instead of unref'd timer. PR-URL: #8703 Fixes: #8700 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: Santiago Gimeno <[email protected]>
1 parent b3fccc2 commit cec5e36

File tree

1 file changed

+10
-15
lines changed

1 file changed

+10
-15
lines changed

test/parallel/test-cluster-worker-init.js

+10-15
Original file line numberDiff line numberDiff line change
@@ -3,30 +3,25 @@
33
// verifies that, when a child process is forked, the cluster.worker
44
// object can receive messages as expected
55

6-
require('../common');
7-
var assert = require('assert');
8-
var cluster = require('cluster');
9-
var msg = 'foo';
6+
const common = require('../common');
7+
const assert = require('assert');
8+
const cluster = require('cluster');
9+
const msg = 'foo';
1010

1111
if (cluster.isMaster) {
12-
var worker = cluster.fork();
13-
var timer = setTimeout(function() {
14-
assert(false, 'message not received');
15-
}, 5000);
12+
const worker = cluster.fork();
1613

17-
timer.unref();
18-
19-
worker.on('message', function(message) {
20-
assert(message, 'did not receive expected message');
14+
worker.on('message', common.mustCall((message) => {
15+
assert.strictEqual(message, true, 'did not receive expected message');
2116
worker.disconnect();
22-
});
17+
}));
2318

24-
worker.on('online', function() {
19+
worker.on('online', () => {
2520
worker.send(msg);
2621
});
2722
} else {
2823
// GH #7998
29-
cluster.worker.on('message', function(message) {
24+
cluster.worker.on('message', (message) => {
3025
process.send(message === msg);
3126
});
3227
}

0 commit comments

Comments
 (0)