From: Jérôme Benoit Date: Sat, 26 Aug 2023 15:14:06 +0000 (+0200) Subject: refactor: cleanup tasks queue options handling X-Git-Tag: v2.6.36~15 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=68dbcdc0bf58d1ff153a505b282f111d53fc3f26;p=poolifier.git refactor: cleanup tasks queue options handling Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 60819027..d415ac9c 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -313,28 +313,22 @@ export abstract class AbstractPool< `Invalid worker node tasks concurrency: ${tasksQueueOptions.concurrency} is a negative integer or zero` ) } - if ( - tasksQueueOptions?.queueMaxSize != null && - tasksQueueOptions?.size != null - ) { + if (tasksQueueOptions?.queueMaxSize != null) { throw new Error( - 'Invalid tasks queue options: cannot specify both queueMaxSize and size' + 'Invalid tasks queue options: queueMaxSize is deprecated, please use size instead' ) } - if (tasksQueueOptions?.queueMaxSize != null) { - tasksQueueOptions.size = tasksQueueOptions.queueMaxSize - } if ( tasksQueueOptions?.size != null && !Number.isSafeInteger(tasksQueueOptions.size) ) { throw new TypeError( - 'Invalid worker node tasks queue max size: must be an integer' + 'Invalid worker node tasks queue size: must be an integer' ) } if (tasksQueueOptions?.size != null && tasksQueueOptions.size <= 0) { throw new RangeError( - `Invalid worker node tasks queue max size: ${tasksQueueOptions.size} is a negative integer or zero` + `Invalid worker node tasks queue size: ${tasksQueueOptions.size} is a negative integer or zero` ) } } @@ -1290,6 +1284,9 @@ export abstract class AbstractPool< } private tasksStealingOnBackPressure (workerId: number): void { + if ((this.opts.tasksQueueOptions?.size as number) <= 1) { + return + } const sourceWorkerNode = this.workerNodes[this.getWorkerNodeKeyByWorkerId(workerId)] const workerNodes = this.workerNodes diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 933e1f94..b777e341 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -544,20 +544,23 @@ describe('Abstract pool test suite', () => { expect(() => pool.setTasksQueueOptions({ concurrency: 0.2 })).toThrowError( new TypeError('Invalid worker node tasks concurrency: must be an integer') ) + expect(() => pool.setTasksQueueOptions({ queueMaxSize: 2 })).toThrowError( + new Error( + 'Invalid tasks queue options: queueMaxSize is deprecated, please use size instead' + ) + ) expect(() => pool.setTasksQueueOptions({ size: 0 })).toThrowError( new RangeError( - 'Invalid worker node tasks queue max size: 0 is a negative integer or zero' + 'Invalid worker node tasks queue size: 0 is a negative integer or zero' ) ) expect(() => pool.setTasksQueueOptions({ size: -1 })).toThrowError( new RangeError( - 'Invalid worker node tasks queue max size: -1 is a negative integer or zero' + 'Invalid worker node tasks queue size: -1 is a negative integer or zero' ) ) expect(() => pool.setTasksQueueOptions({ size: 0.2 })).toThrowError( - new TypeError( - 'Invalid worker node tasks queue max size: must be an integer' - ) + new TypeError('Invalid worker node tasks queue size: must be an integer') ) await pool.destroy() })