From: Jérôme Benoit Date: Thu, 31 Aug 2023 21:25:34 +0000 (+0200) Subject: refactor: untangle worker eligibility from previous worker node X-Git-Tag: v2.6.40~12 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=86ed05989a886c9e44d5be0089d5381debfb2294;p=poolifier.git refactor: untangle worker eligibility from previous worker node assignation Signed-off-by: Jérôme Benoit --- diff --git a/benchmarks/versus-external-pools/package.json b/benchmarks/versus-external-pools/package.json index fef80725..a78d1417 100644 --- a/benchmarks/versus-external-pools/package.json +++ b/benchmarks/versus-external-pools/package.json @@ -12,7 +12,7 @@ }, "volta": { "node": "18.17.1", - "pnpm": "8.7.0" + "pnpm": "8.7.1" }, "scripts": { "test": "echo \"Error: no test specified\" && exit 1" diff --git a/examples/typescript/http-client-pool/package.json b/examples/typescript/http-client-pool/package.json index 34f07622..29f0e15f 100644 --- a/examples/typescript/http-client-pool/package.json +++ b/examples/typescript/http-client-pool/package.json @@ -7,7 +7,7 @@ "type": "module", "volta": { "node": "20.5.1", - "pnpm": "8.7.0" + "pnpm": "8.7.1" }, "scripts": { "build": "pnpm build:clean && tsc", diff --git a/examples/typescript/http-server-pool/express-cluster/package.json b/examples/typescript/http-server-pool/express-cluster/package.json index ddde8848..88a177b7 100644 --- a/examples/typescript/http-server-pool/express-cluster/package.json +++ b/examples/typescript/http-server-pool/express-cluster/package.json @@ -7,7 +7,7 @@ "type": "module", "volta": { "node": "20.5.1", - "pnpm": "8.7.0" + "pnpm": "8.7.1" }, "scripts": { "build": "rollup --config", diff --git a/examples/typescript/http-server-pool/express-hybrid/package.json b/examples/typescript/http-server-pool/express-hybrid/package.json index 18c38580..7863d1ca 100644 --- a/examples/typescript/http-server-pool/express-hybrid/package.json +++ b/examples/typescript/http-server-pool/express-hybrid/package.json @@ -7,7 +7,7 @@ "type": "module", "volta": { "node": "20.5.1", - "pnpm": "8.7.0" + "pnpm": "8.7.1" }, "scripts": { "build": "rollup --config", diff --git a/examples/typescript/http-server-pool/express-worker_threads/package.json b/examples/typescript/http-server-pool/express-worker_threads/package.json index bd5e622d..557698e4 100644 --- a/examples/typescript/http-server-pool/express-worker_threads/package.json +++ b/examples/typescript/http-server-pool/express-worker_threads/package.json @@ -7,7 +7,7 @@ "type": "module", "volta": { "node": "20.5.1", - "pnpm": "8.7.0" + "pnpm": "8.7.1" }, "scripts": { "build": "pnpm build:clean && tsc", diff --git a/examples/typescript/http-server-pool/fastify-cluster/package.json b/examples/typescript/http-server-pool/fastify-cluster/package.json index 6322ff16..cd9e5e50 100644 --- a/examples/typescript/http-server-pool/fastify-cluster/package.json +++ b/examples/typescript/http-server-pool/fastify-cluster/package.json @@ -7,7 +7,7 @@ "type": "module", "volta": { "node": "20.5.1", - "pnpm": "8.7.0" + "pnpm": "8.7.1" }, "scripts": { "build": "rollup --config", diff --git a/examples/typescript/http-server-pool/fastify-hybrid/package.json b/examples/typescript/http-server-pool/fastify-hybrid/package.json index b7ceda4e..57bf2bb4 100644 --- a/examples/typescript/http-server-pool/fastify-hybrid/package.json +++ b/examples/typescript/http-server-pool/fastify-hybrid/package.json @@ -7,7 +7,7 @@ "type": "module", "volta": { "node": "20.5.1", - "pnpm": "8.7.0" + "pnpm": "8.7.1" }, "scripts": { "build": "rollup --config", diff --git a/examples/typescript/http-server-pool/fastify-worker_threads/package.json b/examples/typescript/http-server-pool/fastify-worker_threads/package.json index 8914fc39..3bd5c287 100644 --- a/examples/typescript/http-server-pool/fastify-worker_threads/package.json +++ b/examples/typescript/http-server-pool/fastify-worker_threads/package.json @@ -7,7 +7,7 @@ "type": "module", "volta": { "node": "20.5.1", - "pnpm": "8.7.0" + "pnpm": "8.7.1" }, "scripts": { "build": "pnpm build:clean && tsc", diff --git a/examples/typescript/smtp-client-pool/package.json b/examples/typescript/smtp-client-pool/package.json index 3e15f2a5..2e1b61b8 100644 --- a/examples/typescript/smtp-client-pool/package.json +++ b/examples/typescript/smtp-client-pool/package.json @@ -7,7 +7,7 @@ "type": "module", "volta": { "node": "20.5.1", - "pnpm": "8.7.0" + "pnpm": "8.7.1" }, "scripts": { "build": "pnpm build:clean && tsc", diff --git a/examples/typescript/websocket-server-pool/ws-cluster/package.json b/examples/typescript/websocket-server-pool/ws-cluster/package.json index 96d24cd9..cb0afd39 100644 --- a/examples/typescript/websocket-server-pool/ws-cluster/package.json +++ b/examples/typescript/websocket-server-pool/ws-cluster/package.json @@ -7,7 +7,7 @@ "type": "module", "volta": { "node": "20.5.1", - "pnpm": "8.7.0" + "pnpm": "8.7.1" }, "scripts": { "build": "rollup --config", diff --git a/examples/typescript/websocket-server-pool/ws-hybrid/package.json b/examples/typescript/websocket-server-pool/ws-hybrid/package.json index 952fae55..52a0cb14 100644 --- a/examples/typescript/websocket-server-pool/ws-hybrid/package.json +++ b/examples/typescript/websocket-server-pool/ws-hybrid/package.json @@ -7,7 +7,7 @@ "type": "module", "volta": { "node": "20.5.1", - "pnpm": "8.7.0" + "pnpm": "8.7.1" }, "scripts": { "build": "rollup --config", diff --git a/examples/typescript/websocket-server-pool/ws-worker_threads/package.json b/examples/typescript/websocket-server-pool/ws-worker_threads/package.json index 3bc5ccd7..db1e5029 100644 --- a/examples/typescript/websocket-server-pool/ws-worker_threads/package.json +++ b/examples/typescript/websocket-server-pool/ws-worker_threads/package.json @@ -7,7 +7,7 @@ "type": "module", "volta": { "node": "20.5.1", - "pnpm": "8.7.0" + "pnpm": "8.7.1" }, "scripts": { "build": "pnpm build:clean && tsc", diff --git a/package.json b/package.json index d776fa11..fb6509c1 100644 --- a/package.json +++ b/package.json @@ -50,7 +50,7 @@ }, "volta": { "node": "20.5.1", - "pnpm": "8.7.0" + "pnpm": "8.7.1" }, "repository": { "type": "git", diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 7075bc6c..a9632d87 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -1437,7 +1437,7 @@ export abstract class AbstractPool< this.workerNodes.push(workerNode) const workerNodeKey = this.getWorkerNodeKeyByWorker(worker) if (workerNodeKey === -1) { - throw new Error('Worker node added not found') + throw new Error('Worker added not found in worker nodes') } return workerNodeKey } diff --git a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts index ca3d9b9d..3c41dd6f 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -205,15 +205,10 @@ export abstract class AbstractWorkerChoiceStrategy< /** * Check the next worker node eligibility. - * - * @param previousWorkerNodeKey - The previous worker node key. */ - protected checkNextWorkerNodeEligibility ( - previousWorkerNodeKey: number | undefined - ): void { + protected checkNextWorkerNodeEligibility (): void { if (!this.isWorkerNodeEligible(this.nextWorkerNodeKey as number)) { this.nextWorkerNodeKey = undefined - this.setPreviousWorkerNodeKey(previousWorkerNodeKey) } } diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index daa1b4e7..055a2dbb 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -413,6 +413,16 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js', { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN } ) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).nextWorkerNodeKey + ).toBeDefined() + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toBeDefined() pool.setWorkerChoiceStrategy(workerChoiceStrategy) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -431,6 +441,16 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.js', { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN } ) + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).nextWorkerNodeKey + ).toBeDefined() + expect( + pool.workerChoiceStrategyContext.workerChoiceStrategies.get( + pool.workerChoiceStrategyContext.workerChoiceStrategy + ).previousWorkerNodeKey + ).toBeDefined() pool.setWorkerChoiceStrategy(workerChoiceStrategy) expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get(