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: improve test-cluster-disconnect-suicide-race #4739

Closed
wants to merge 2 commits 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
41 changes: 18 additions & 23 deletions test/sequential/test-cluster-disconnect-suicide-race.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,27 @@
'use strict';

// Test should fail in Node.js 5.4.1 and pass in later versions.

const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');
const os = require('os');

if (cluster.isMaster) {
function forkWorker(action) {
const worker = cluster.fork({ action });
worker.on('disconnect', common.mustCall(() => {
assert.strictEqual(worker.suicide, true);
}));
cluster.on('exit', (worker, code) => {
assert.strictEqual(code, 0, 'worker exited with error');
});

return cluster.fork();
}

worker.on('exit', common.mustCall(() => {
assert.strictEqual(worker.suicide, true);
}));
}
var eventFired = false;

const cpus = os.cpus().length;
const tries = cpus > 8 ? 64 : cpus * 8;
cluster.worker.disconnect();

cluster.on('exit', common.mustCall((worker, code) => {
assert.strictEqual(code, 0, 'worker exited with error');
}, tries * 2));

for (let i = 0; i < tries; ++i) {
forkWorker('disconnect');
forkWorker('kill');
}
} else {
cluster.worker[process.env.action]();
}
process.nextTick(common.mustCall(() => {
assert.strictEqual(eventFired, false, 'disconnect event should wait for ack');
}));

cluster.worker.on('disconnect', common.mustCall(() => {
eventFired = true;
}));