diff --git a/test/sequential/test-cluster-disconnect-suicide-race.js b/test/sequential/test-cluster-disconnect-suicide-race.js index e05c420e1fdd9b..6f23b23fd2d4ff 100644 --- a/test/sequential/test-cluster-disconnect-suicide-race.js +++ b/test/sequential/test-cluster-disconnect-suicide-race.js @@ -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; +}));