diff options
-rw-r--r-- | doc/api/cluster.md | 2 | ||||
-rw-r--r-- | lib/cluster.js | 2 | ||||
-rw-r--r-- | test/parallel/test-cluster-worker-destroy.js | 4 | ||||
-rw-r--r-- | test/parallel/test-cluster-worker-disconnect.js | 3 | ||||
-rw-r--r-- | test/parallel/test-cluster-worker-init.js | 3 |
5 files changed, 11 insertions, 3 deletions
diff --git a/doc/api/cluster.md b/doc/api/cluster.md index c323282d0f9..f3c8017da1e 100644 --- a/doc/api/cluster.md +++ b/doc/api/cluster.md @@ -257,6 +257,8 @@ It is not emitted in the worker. added: v0.7.7 --> +* Returns: {Worker} A reference to `worker`. + In a worker, this function will close all servers, wait for the `'close'` event on those servers, and then disconnect the IPC channel. diff --git a/lib/cluster.js b/lib/cluster.js index 67e88339417..e95e19bcc67 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -430,6 +430,7 @@ function masterInit() { send(this, { act: 'disconnect' }); removeHandlesForWorker(this); removeWorker(this); + return this; }; Worker.prototype.destroy = function(signo) { @@ -687,6 +688,7 @@ function workerInit() { Worker.prototype.disconnect = function() { _disconnect.call(this); + return this; }; Worker.prototype.destroy = function() { diff --git a/test/parallel/test-cluster-worker-destroy.js b/test/parallel/test-cluster-worker-destroy.js index c802177530e..ca3ac77e7b2 100644 --- a/test/parallel/test-cluster-worker-destroy.js +++ b/test/parallel/test-cluster-worker-destroy.js @@ -8,6 +8,7 @@ */ const common = require('../common'); +const assert = require('assert'); var cluster = require('cluster'); var worker1, worker2; @@ -26,7 +27,8 @@ if (cluster.isMaster) { cluster.worker.destroy(); }); - cluster.worker.disconnect(); + const w = cluster.worker.disconnect(); + assert.strictEqual(w, cluster.worker, 'did not return a reference'); } else { // Call destroy when worker is not disconnected yet cluster.worker.destroy(); diff --git a/test/parallel/test-cluster-worker-disconnect.js b/test/parallel/test-cluster-worker-disconnect.js index 4e17a7d475e..684fd5541ea 100644 --- a/test/parallel/test-cluster-worker-disconnect.js +++ b/test/parallel/test-cluster-worker-disconnect.js @@ -40,7 +40,8 @@ if (cluster.isWorker) { // Disconnect worker when it is ready worker.once('listening', common.mustCall(() => { - worker.disconnect(); + const w = worker.disconnect(); + assert.strictEqual(worker, w, 'did not return a reference'); })); // Check cluster events diff --git a/test/parallel/test-cluster-worker-init.js b/test/parallel/test-cluster-worker-init.js index 3b82866d1b1..eaa9746c5f9 100644 --- a/test/parallel/test-cluster-worker-init.js +++ b/test/parallel/test-cluster-worker-init.js @@ -13,7 +13,8 @@ if (cluster.isMaster) { worker.on('message', common.mustCall((message) => { assert.strictEqual(message, true, 'did not receive expected message'); - worker.disconnect(); + const w = worker.disconnect(); + assert.strictEqual(worker, w, 'did not return a reference'); })); worker.on('online', () => { |