Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

test: fix test-cluster-worker-init.js flakyness #8703

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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);
});
}