From: Jérôme Benoit Date: Sat, 26 Aug 2023 19:30:11 +0000 (+0200) Subject: test: improve coverage X-Git-Tag: v2.6.36~9 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=7e653ee033b398cb5877b21dcab0bfe4bf1d7721;p=poolifier.git test: improve coverage Signed-off-by: Jérôme Benoit --- 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(