From 4323c8018e4f6cffa2da6a53b7de176d5d1396c4 Mon Sep 17 00:00:00 2001 From: Rich Trott Date: Fri, 6 Jan 2017 21:40:51 -0800 Subject: [PATCH] test,cluster: add test-cluster-worker-deprecated Add test to cover setter for deprecated cluster Worker property. Previously, the setter was not being exercised in tests. PR-URL: https://github.com/nodejs/node/pull/10675 Reviewed-By: James M Snell Reviewed-By: Sam Roberts --- lib/cluster.js | 14 ++++++-------- .../parallel/test-cluster-worker-deprecated.js | 18 ++++++++++++++++++ 2 files changed, 24 insertions(+), 8 deletions(-) create mode 100644 test/parallel/test-cluster-worker-deprecated.js diff --git a/lib/cluster.js b/lib/cluster.js index e95e19bcc672d4..a12b83cd0c34c0 100644 --- a/lib/cluster.js +++ b/lib/cluster.js @@ -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 }); diff --git a/test/parallel/test-cluster-worker-deprecated.js b/test/parallel/test-cluster-worker-deprecated.js new file mode 100644 index 00000000000000..2f433aae797ccc --- /dev/null +++ b/test/parallel/test-cluster-worker-deprecated.js @@ -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');