From: Jérôme Benoit Date: Sat, 8 Jul 2023 23:10:44 +0000 (+0200) Subject: fix: fix pool readiness semantic X-Git-Tag: v2.6.11~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=d5024c00ac9148ad6b8a10b49c548562948554e2;p=poolifier.git fix: fix pool readiness semantic Signed-off-by: Jérôme Benoit --- 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,