From 7e653ee033b398cb5877b21dcab0bfe4bf1d7721 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 26 Aug 2023 21:30:11 +0200 Subject: [PATCH] test: improve coverage MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 4 +- tests/pools/abstract/abstract-pool.test.js | 48 ++++++++++++++++++++++ 2 files changed, 50 insertions(+), 2 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index afcf611e..f862bbbe 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -265,10 +265,10 @@ export abstract class AbstractPool< } if ( workerChoiceStrategyOptions.choiceRetries != null && - workerChoiceStrategyOptions.choiceRetries <= 0 + workerChoiceStrategyOptions.choiceRetries < 0 ) { throw new RangeError( - `Invalid worker choice strategy options: choice retries '${workerChoiceStrategyOptions.choiceRetries}' must be greater than zero` + `Invalid worker choice strategy options: choice retries '${workerChoiceStrategyOptions.choiceRetries}' must be greater or equal than zero` ) } if ( diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 2fa22471..0890d564 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -257,6 +257,38 @@ describe('Abstract pool test suite', () => { ).toThrowError( new Error("Invalid worker choice strategy 'invalidStrategy'") ) + expect( + () => + new FixedThreadPool( + numberOfWorkers, + './tests/worker-files/thread/testWorker.js', + { + workerChoiceStrategyOptions: { + choiceRetries: 'invalidChoiceRetries' + } + } + ) + ).toThrowError( + new TypeError( + 'Invalid worker choice strategy options: choice retries must be an integer' + ) + ) + expect( + () => + new FixedThreadPool( + numberOfWorkers, + './tests/worker-files/thread/testWorker.js', + { + workerChoiceStrategyOptions: { + choiceRetries: -1 + } + } + ) + ).toThrowError( + new RangeError( + "Invalid worker choice strategy options: choice retries '-1' must be greater or equal than zero" + ) + ) expect( () => new FixedThreadPool( @@ -469,6 +501,22 @@ describe('Abstract pool test suite', () => { 'Invalid worker choice strategy options: must be a plain object' ) ) + expect(() => + pool.setWorkerChoiceStrategyOptions({ + choiceRetries: 'invalidChoiceRetries' + }) + ).toThrowError( + new TypeError( + 'Invalid worker choice strategy options: choice retries must be an integer' + ) + ) + expect(() => + pool.setWorkerChoiceStrategyOptions({ choiceRetries: -1 }) + ).toThrowError( + new RangeError( + "Invalid worker choice strategy options: choice retries '-1' must be greater or equal than zero" + ) + ) expect(() => pool.setWorkerChoiceStrategyOptions({ weights: {} }) ).toThrowError( -- 2.34.1