0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-30 07:27:22 +01:00
nodejs/test/parallel/test-cluster-worker-init.js
Ilkka Myller 66369d05a2 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>
2016-09-24 01:59:12 +03:00

28 lines
675 B
JavaScript

'use strict';
// test-cluster-worker-init.js
// verifies that, when a child process is forked, the cluster.worker
// object can receive messages as expected
const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');
const msg = 'foo';
if (cluster.isMaster) {
const worker = cluster.fork();
worker.on('message', common.mustCall((message) => {
assert.strictEqual(message, true, 'did not receive expected message');
worker.disconnect();
}));
worker.on('online', () => {
worker.send(msg);
});
} else {
// GH #7998
cluster.worker.on('message', (message) => {
process.send(message === msg);
});
}