Browse Source

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: https://github.com/nodejs/node/pull/8703
Fixes: https://github.com/nodejs/node/issues/8700
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
v6.x
Ilkka Myller 8 years ago
committed by Jeremiah Senkpiel
parent
commit
5540e3d488
  1. 25
      test/parallel/test-cluster-worker-init.js

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

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

Loading…
Cancel
Save