Skip to content

Commit

Permalink
test: fix test-cluster-worker-init.js flakyness
Browse files Browse the repository at this point in the history
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 <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
  • Loading branch information
imyller authored and Myles Borins committed Nov 18, 2016
1 parent b3fccc2 commit cec5e36
Showing 1 changed file with 10 additions and 15 deletions.
25 changes: 10 additions & 15 deletions test/parallel/test-cluster-worker-init.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,25 @@
// verifies that, when a child process is forked, the cluster.worker
// object can receive messages as expected

require('../common');
var assert = require('assert');
var cluster = require('cluster');
var msg = 'foo';
const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');
const msg = 'foo';

if (cluster.isMaster) {
var worker = cluster.fork();
var timer = setTimeout(function() {
assert(false, 'message not received');
}, 5000);
const worker = cluster.fork();

timer.unref();

worker.on('message', function(message) {
assert(message, 'did not receive expected message');
worker.on('message', common.mustCall((message) => {
assert.strictEqual(message, true, 'did not receive expected message');
worker.disconnect();
});
}));

worker.on('online', function() {
worker.on('online', () => {
worker.send(msg);
});
} else {
// GH #7998
cluster.worker.on('message', function(message) {
cluster.worker.on('message', (message) => {
process.send(message === msg);
});
}

0 comments on commit cec5e36

Please sign in to comment.