From 61bb1f58f6576a895725983b050bec116b8b1319 Mon Sep 17 00:00:00 2001 From: Igor Klopov Date: Sat, 13 Feb 2016 06:35:40 -0500 Subject: [PATCH 1/2] cluster: dont rely `fork` on `this` --- lib/cluster.js | 2 +- test/parallel/test-cluster-disconnect-idle-worker.js | 5 +++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/lib/cluster.js b/lib/cluster.js index c8bf658d5b32a8..4f7ca58170468f 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -342,7 +342,7 @@ function masterInit() { }); worker.on('message', (message, handle) => - this.emit('message', message, handle) + cluster.emit('message', message, handle) ); worker.process.once('exit', function(exitCode, signalCode) { diff --git a/test/parallel/test-cluster-disconnect-idle-worker.js b/test/parallel/test-cluster-disconnect-idle-worker.js index e18c05004467b7..3630af81cdf34e 100644 --- a/test/parallel/test-cluster-disconnect-idle-worker.js +++ b/test/parallel/test-cluster-disconnect-idle-worker.js @@ -2,10 +2,11 @@ var common = require('../common'); var assert = require('assert'); var cluster = require('cluster'); +var fork = cluster.fork; if (cluster.isMaster) { - cluster.fork(); - cluster.fork(); + fork(); + fork(); cluster.disconnect(common.mustCall(function() { assert.deepEqual(Object.keys(cluster.workers), []); })); From 17e360450ed8413c4efefe12cc46bc382246964b Mon Sep 17 00:00:00 2001 From: Igor Klopov Date: Mon, 15 Feb 2016 20:26:27 +0300 Subject: [PATCH 2/2] cluster: added a message to prevent cleanup --- test/parallel/test-cluster-disconnect-idle-worker.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/test/parallel/test-cluster-disconnect-idle-worker.js b/test/parallel/test-cluster-disconnect-idle-worker.js index 3630af81cdf34e..c4a310a9d07268 100644 --- a/test/parallel/test-cluster-disconnect-idle-worker.js +++ b/test/parallel/test-cluster-disconnect-idle-worker.js @@ -5,8 +5,8 @@ var cluster = require('cluster'); var fork = cluster.fork; if (cluster.isMaster) { - fork(); - fork(); + fork(); // it is intentionally called `fork` instead of + fork(); // `cluster.fork` to test that `this` is not used cluster.disconnect(common.mustCall(function() { assert.deepEqual(Object.keys(cluster.workers), []); }));