From d5024c00ac9148ad6b8a10b49c548562948554e2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 9 Jul 2023 01:10:44 +0200 Subject: [PATCH] fix: fix pool readiness semantic MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- CHANGELOG.md | 4 ++++ src/pools/abstract-pool.ts | 8 +++++--- src/pools/pool.ts | 2 +- tests/pools/abstract/abstract-pool.test.js | 5 +++-- 4 files changed, 13 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index c6eca042..1601bc78 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +### Fixed + +- Fix pool readiness semantic. + ## [2.6.10] - 2023-07-08 ### Fixed diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 19272508..c699b528 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -403,14 +403,16 @@ export abstract class AbstractPool< private get starting (): boolean { return ( - !this.full || - (this.full && this.workerNodes.some(workerNode => !workerNode.info.ready)) + this.workerNodes.length < this.minSize || + (this.workerNodes.length >= this.minSize && + this.workerNodes.some(workerNode => !workerNode.info.ready)) ) } private get ready (): boolean { return ( - this.full && this.workerNodes.every(workerNode => workerNode.info.ready) + this.workerNodes.length >= this.minSize && + this.workerNodes.every(workerNode => workerNode.info.ready) ) } diff --git a/src/pools/pool.ts b/src/pools/pool.ts index 78d298f9..881ea62a 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -183,7 +183,7 @@ export interface IPool< * Events that can currently be listened to: * * - `'full'`: Emitted when the pool is dynamic and the number of workers created has reached the maximum size expected. - * - `'ready'`: Emitted when the number of workers created in the pool has reached the maximum size expected and are ready. + * - `'ready'`: Emitted when the number of workers created in the pool has reached the minimum size expected and are ready. * - `'busy'`: Emitted when the number of workers created in the pool has reached the maximum size expected and are executing at least one task. * - `'error'`: Emitted when an uncaught error occurs. * - `'taskError'`: Emitted when an error occurs while executing a task. diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index a62caad8..349521d2 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -720,7 +720,8 @@ describe('Abstract pool test suite', () => { }) it("Verify that pool event emitter 'ready' event can register a callback", async () => { - const pool = new FixedClusterPool( + const pool = new DynamicClusterPool( + Math.floor(numberOfWorkers / 2), numberOfWorkers, './tests/worker-files/cluster/testWorker.js' ) @@ -734,7 +735,7 @@ describe('Abstract pool test suite', () => { expect(poolReady).toBe(1) expect(poolInfo).toStrictEqual({ version, - type: PoolTypes.fixed, + type: PoolTypes.dynamic, worker: WorkerTypes.cluster, ready: true, strategy: WorkerChoiceStrategies.ROUND_ROBIN, -- 2.34.1