From cca3bb1a52271e1b74e3929524faf61521e5c888 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 29 Aug 2023 14:25:20 +0200 Subject: [PATCH] test: remove 2 unneeded UTs MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- tests/pools/abstract/abstract-pool.test.js | 3 ++- .../worker-files/cluster/asyncErrorWorker.js | 4 ++-- tests/worker-files/cluster/asyncWorker.js | 4 ++-- tests/worker-files/cluster/emptyWorker.js | 4 ++-- tests/worker-files/cluster/errorWorker.js | 4 ++-- .../cluster/longRunningWorkerHardBehavior.js | 4 ++-- .../testMultipleTaskFunctionsWorker.js | 4 ++-- tests/worker-files/cluster/testWorker.js | 4 ++-- tests/worker-files/thread/asyncErrorWorker.js | 4 ++-- tests/worker-files/thread/asyncWorker.js | 4 ++-- tests/worker-files/thread/emptyWorker.js | 4 ++-- tests/worker-files/thread/errorWorker.js | 4 ++-- .../thread/longRunningWorkerHardBehavior.js | 4 ++-- .../thread/testMultipleTaskFunctionsWorker.js | 4 ++-- tests/worker-files/thread/testWorker.js | 4 ++-- tests/worker/abstract-worker.test.js | 20 ++++++++++--------- tests/worker/cluster-worker.test.js | 5 ----- tests/worker/thread-worker.test.js | 5 ----- 18 files changed, 41 insertions(+), 48 deletions(-) diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 2fac7f58..2a6ba858 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -1,3 +1,4 @@ +const { EventEmitter } = require('events') const { expect } = require('expect') const sinon = require('sinon') const { @@ -178,7 +179,7 @@ describe('Abstract pool test suite', () => { numberOfWorkers, './tests/worker-files/thread/testWorker.js' ) - expect(pool.emitter).toBeDefined() + expect(pool.emitter).toBeInstanceOf(EventEmitter) expect(pool.opts.enableEvents).toBe(true) expect(pool.opts.restartWorkerOnError).toBe(true) expect(pool.opts.enableTasksQueue).toBe(false) diff --git a/tests/worker-files/cluster/asyncErrorWorker.js b/tests/worker-files/cluster/asyncErrorWorker.js index 028a7cf3..468a0ff9 100644 --- a/tests/worker-files/cluster/asyncErrorWorker.js +++ b/tests/worker-files/cluster/asyncErrorWorker.js @@ -12,6 +12,6 @@ async function error (data) { } module.exports = new ClusterWorker(error, { - maxInactiveTime: 500, - killBehavior: KillBehaviors.HARD + killBehavior: KillBehaviors.HARD, + maxInactiveTime: 500 }) diff --git a/tests/worker-files/cluster/asyncWorker.js b/tests/worker-files/cluster/asyncWorker.js index b03a5054..f07625bd 100644 --- a/tests/worker-files/cluster/asyncWorker.js +++ b/tests/worker-files/cluster/asyncWorker.js @@ -7,6 +7,6 @@ async function sleep (data) { } module.exports = new ClusterWorker(sleep, { - maxInactiveTime: 500, - killBehavior: KillBehaviors.HARD + killBehavior: KillBehaviors.HARD, + maxInactiveTime: 500 }) diff --git a/tests/worker-files/cluster/emptyWorker.js b/tests/worker-files/cluster/emptyWorker.js index 01d1cf09..02a733da 100644 --- a/tests/worker-files/cluster/emptyWorker.js +++ b/tests/worker-files/cluster/emptyWorker.js @@ -4,6 +4,6 @@ const { ClusterWorker, KillBehaviors } = require('../../../lib') function test () {} module.exports = new ClusterWorker(test, { - maxInactiveTime: 500, - killBehavior: KillBehaviors.HARD + killBehavior: KillBehaviors.HARD, + maxInactiveTime: 500 }) diff --git a/tests/worker-files/cluster/errorWorker.js b/tests/worker-files/cluster/errorWorker.js index 01cffc5e..b8e11d36 100644 --- a/tests/worker-files/cluster/errorWorker.js +++ b/tests/worker-files/cluster/errorWorker.js @@ -6,6 +6,6 @@ function error () { } module.exports = new ClusterWorker(error, { - maxInactiveTime: 500, - killBehavior: KillBehaviors.HARD + killBehavior: KillBehaviors.HARD, + maxInactiveTime: 500 }) diff --git a/tests/worker-files/cluster/longRunningWorkerHardBehavior.js b/tests/worker-files/cluster/longRunningWorkerHardBehavior.js index f2c0c1e4..ee6b93cc 100644 --- a/tests/worker-files/cluster/longRunningWorkerHardBehavior.js +++ b/tests/worker-files/cluster/longRunningWorkerHardBehavior.js @@ -7,6 +7,6 @@ async function sleep (data) { } module.exports = new ClusterWorker(sleep, { - maxInactiveTime: 500, - killBehavior: KillBehaviors.HARD + killBehavior: KillBehaviors.HARD, + maxInactiveTime: 500 }) diff --git a/tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js b/tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js index 5072691b..2bb525e2 100644 --- a/tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js +++ b/tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js @@ -13,7 +13,7 @@ module.exports = new ClusterWorker( fibonacci: (data) => fibonacci(data.n) }, { - maxInactiveTime: 500, - killBehavior: KillBehaviors.HARD + killBehavior: KillBehaviors.HARD, + maxInactiveTime: 500 } ) diff --git a/tests/worker-files/cluster/testWorker.js b/tests/worker-files/cluster/testWorker.js index 8462307c..4511bcaa 100644 --- a/tests/worker-files/cluster/testWorker.js +++ b/tests/worker-files/cluster/testWorker.js @@ -10,6 +10,6 @@ function test (data) { } module.exports = new ClusterWorker(test, { - maxInactiveTime: 500, - killBehavior: KillBehaviors.HARD + killBehavior: KillBehaviors.HARD, + maxInactiveTime: 500 }) diff --git a/tests/worker-files/thread/asyncErrorWorker.js b/tests/worker-files/thread/asyncErrorWorker.js index c73fd291..f696b101 100644 --- a/tests/worker-files/thread/asyncErrorWorker.js +++ b/tests/worker-files/thread/asyncErrorWorker.js @@ -12,6 +12,6 @@ async function error (data) { } module.exports = new ThreadWorker(error, { - maxInactiveTime: 500, - killBehavior: KillBehaviors.HARD + killBehavior: KillBehaviors.HARD, + maxInactiveTime: 500 }) diff --git a/tests/worker-files/thread/asyncWorker.js b/tests/worker-files/thread/asyncWorker.js index 2b834b87..c3bcdc8d 100644 --- a/tests/worker-files/thread/asyncWorker.js +++ b/tests/worker-files/thread/asyncWorker.js @@ -7,6 +7,6 @@ async function sleep (data) { } module.exports = new ThreadWorker(sleep, { - maxInactiveTime: 500, - killBehavior: KillBehaviors.HARD + killBehavior: KillBehaviors.HARD, + maxInactiveTime: 500 }) diff --git a/tests/worker-files/thread/emptyWorker.js b/tests/worker-files/thread/emptyWorker.js index cb076770..d77b472d 100644 --- a/tests/worker-files/thread/emptyWorker.js +++ b/tests/worker-files/thread/emptyWorker.js @@ -4,6 +4,6 @@ const { ThreadWorker, KillBehaviors } = require('../../../lib') function test () {} module.exports = new ThreadWorker(test, { - maxInactiveTime: 500, - killBehavior: KillBehaviors.HARD + killBehavior: KillBehaviors.HARD, + maxInactiveTime: 500 }) diff --git a/tests/worker-files/thread/errorWorker.js b/tests/worker-files/thread/errorWorker.js index 19785dc3..e5738982 100644 --- a/tests/worker-files/thread/errorWorker.js +++ b/tests/worker-files/thread/errorWorker.js @@ -6,6 +6,6 @@ function error () { } module.exports = new ThreadWorker(error, { - maxInactiveTime: 500, - killBehavior: KillBehaviors.HARD + killBehavior: KillBehaviors.HARD, + maxInactiveTime: 500 }) diff --git a/tests/worker-files/thread/longRunningWorkerHardBehavior.js b/tests/worker-files/thread/longRunningWorkerHardBehavior.js index daa381ed..e7d84df9 100644 --- a/tests/worker-files/thread/longRunningWorkerHardBehavior.js +++ b/tests/worker-files/thread/longRunningWorkerHardBehavior.js @@ -7,6 +7,6 @@ async function sleep (data) { } module.exports = new ThreadWorker(sleep, { - maxInactiveTime: 500, - killBehavior: KillBehaviors.HARD + killBehavior: KillBehaviors.HARD, + maxInactiveTime: 500 }) diff --git a/tests/worker-files/thread/testMultipleTaskFunctionsWorker.js b/tests/worker-files/thread/testMultipleTaskFunctionsWorker.js index f2275269..188c8e53 100644 --- a/tests/worker-files/thread/testMultipleTaskFunctionsWorker.js +++ b/tests/worker-files/thread/testMultipleTaskFunctionsWorker.js @@ -13,7 +13,7 @@ module.exports = new ThreadWorker( fibonacci: (data) => fibonacci(data.n) }, { - maxInactiveTime: 500, - killBehavior: KillBehaviors.HARD + killBehavior: KillBehaviors.HARD, + maxInactiveTime: 500 } ) diff --git a/tests/worker-files/thread/testWorker.js b/tests/worker-files/thread/testWorker.js index 64e7921a..3945589f 100644 --- a/tests/worker-files/thread/testWorker.js +++ b/tests/worker-files/thread/testWorker.js @@ -10,6 +10,6 @@ function test (data) { } module.exports = new ThreadWorker(test, { - maxInactiveTime: 500, - killBehavior: KillBehaviors.HARD + killBehavior: KillBehaviors.HARD, + maxInactiveTime: 500 }) diff --git a/tests/worker/abstract-worker.test.js b/tests/worker/abstract-worker.test.js index 0a920dd5..62f6dd2b 100644 --- a/tests/worker/abstract-worker.test.js +++ b/tests/worker/abstract-worker.test.js @@ -17,10 +17,11 @@ describe('Abstract worker test suite', () => { it('Verify worker options default values', () => { const worker = new ThreadWorker(() => {}) - expect(worker.opts.maxInactiveTime).toStrictEqual(60000) - expect(worker.opts.killBehavior).toBe(KillBehaviors.SOFT) - expect(worker.opts.killHandler).toStrictEqual(EMPTY_FUNCTION) - expect(worker.opts.async).toBe(undefined) + expect(worker.opts).toStrictEqual({ + killBehavior: KillBehaviors.SOFT, + maxInactiveTime: 60000, + killHandler: EMPTY_FUNCTION + }) }) it('Verify that worker options are set at worker creation', () => { @@ -28,15 +29,16 @@ describe('Abstract worker test suite', () => { console.info('Worker received kill message') } const worker = new ClusterWorker(() => {}, { - maxInactiveTime: 6000, killBehavior: KillBehaviors.HARD, + maxInactiveTime: 6000, killHandler, async: true }) - expect(worker.opts.maxInactiveTime).toStrictEqual(6000) - expect(worker.opts.killBehavior).toBe(KillBehaviors.HARD) - expect(worker.opts.killHandler).toStrictEqual(killHandler) - expect(worker.opts.async).toBe(undefined) + expect(worker.opts).toStrictEqual({ + killBehavior: KillBehaviors.HARD, + maxInactiveTime: 6000, + killHandler + }) }) it('Verify that taskFunctions parameter is mandatory', () => { diff --git a/tests/worker/cluster-worker.test.js b/tests/worker/cluster-worker.test.js index 6bbf3246..f857412b 100644 --- a/tests/worker/cluster-worker.test.js +++ b/tests/worker/cluster-worker.test.js @@ -12,11 +12,6 @@ describe('Cluster worker test suite', () => { } } - it('Verify worker has default maxInactiveTime', () => { - const worker = new ClusterWorker(() => {}) - expect(worker.opts.maxInactiveTime).toStrictEqual(60000) - }) - it('Verify worker invokes the getMainWorker() and send() methods', () => { const worker = new SpyWorker(() => {}) worker.sendToMainWorker({ ok: 1 }) diff --git a/tests/worker/thread-worker.test.js b/tests/worker/thread-worker.test.js index 072617d3..495e10b1 100644 --- a/tests/worker/thread-worker.test.js +++ b/tests/worker/thread-worker.test.js @@ -13,11 +13,6 @@ describe('Thread worker test suite', () => { } } - it('Verify worker has default maxInactiveTime', () => { - const worker = new ThreadWorker(() => {}) - expect(worker.opts.maxInactiveTime).toStrictEqual(60000) - }) - it('Verify that handleError() method is working properly', () => { const error = new Error('Error as an error') const worker = new ThreadWorker(() => {}) -- 2.34.1