Skip to content

Commit

Permalink
test,cluster: add test-cluster-worker-deprecated
Browse files Browse the repository at this point in the history
Add test to cover setter for deprecated cluster Worker property.
Previously, the setter was not being exercised in tests.

PR-URL: #10675
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Sam Roberts <vieuxtech@gmail.com>
  • Loading branch information
Trott authored and italoacasas committed Jan 27, 2017
1 parent cf5579d commit 4323c80
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 8 deletions.
14 changes: 6 additions & 8 deletions lib/cluster.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,14 +31,12 @@ function Worker(options) {
this.exitedAfterDisconnect = undefined;

Object.defineProperty(this, 'suicide', {
get: internalUtil.deprecate(() => {
return this.exitedAfterDisconnect;
}, 'worker.suicide is deprecated. ' +
'Please use worker.exitedAfterDisconnect.'),
set: internalUtil.deprecate((val) => {
this.exitedAfterDisconnect = val;
}, 'worker.suicide is deprecated. ' +
'Please use worker.exitedAfterDisconnect.'),
get: internalUtil.deprecate(
() => this.exitedAfterDisconnect,
'worker.suicide is deprecated. Please use worker.exitedAfterDisconnect.'),
set: internalUtil.deprecate(
(val) => { this.exitedAfterDisconnect = val; },
'worker.suicide is deprecated. Please use worker.exitedAfterDisconnect.'),
enumerable: true
});

Expand Down
18 changes: 18 additions & 0 deletions test/parallel/test-cluster-worker-deprecated.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
'use strict';
require('../common');

const assert = require('assert');
const cluster = require('cluster');

const worker = new cluster.Worker();

assert.strictEqual(worker.exitedAfterDisconnect, undefined);
assert.strictEqual(worker.suicide, undefined);

worker.exitedAfterDisconnect = 'recommended';
assert.strictEqual(worker.exitedAfterDisconnect, 'recommended');
assert.strictEqual(worker.suicide, 'recommended');

worker.suicide = 'deprecated';
assert.strictEqual(worker.exitedAfterDisconnect, 'deprecated');
assert.strictEqual(worker.suicide, 'deprecated');

0 comments on commit 4323c80

Please sign in to comment.