From 68dbcdc0bf58d1ff153a505b282f111d53fc3f26 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 26 Aug 2023 17:14:06 +0200 Subject: [PATCH] refactor: cleanup tasks queue options handling 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 | 17 +++++++---------- tests/pools/abstract/abstract-pool.test.js | 13 ++++++++----- 2 files changed, 15 insertions(+), 15 deletions(-) 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() }) -- 2.34.1