refactor: untangle worker eligibility from previous worker node
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 31 Aug 2023 21:25:34 +0000 (23:25 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 31 Aug 2023 21:25:34 +0000 (23:25 +0200)
assignation

Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
16 files changed:
benchmarks/versus-external-pools/package.json
examples/typescript/http-client-pool/package.json
examples/typescript/http-server-pool/express-cluster/package.json
examples/typescript/http-server-pool/express-hybrid/package.json
examples/typescript/http-server-pool/express-worker_threads/package.json
examples/typescript/http-server-pool/fastify-cluster/package.json
examples/typescript/http-server-pool/fastify-hybrid/package.json
examples/typescript/http-server-pool/fastify-worker_threads/package.json
examples/typescript/smtp-client-pool/package.json
examples/typescript/websocket-server-pool/ws-cluster/package.json
examples/typescript/websocket-server-pool/ws-hybrid/package.json
examples/typescript/websocket-server-pool/ws-worker_threads/package.json
package.json
src/pools/abstract-pool.ts
src/pools/selection-strategies/abstract-worker-choice-strategy.ts
tests/pools/selection-strategies/selection-strategies.test.js

index fef80725d03cbe0e98e79900fa9bb24ef68c437f..a78d1417328aaae0b85edffb6ffc43bf84aab5a0 100644 (file)
@@ -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"
index 34f07622a240293ec88b8450e61fe88f5af1ea56..29f0e15f436d0bb7559b5d776458664e31bcdcbd 100644 (file)
@@ -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",
index ddde88486c3b35afa3000eef08088a812c5975fb..88a177b7587ad4603b527ba50c5683e240b085be 100644 (file)
@@ -7,7 +7,7 @@
   "type": "module",
   "volta": {
     "node": "20.5.1",
-    "pnpm": "8.7.0"
+    "pnpm": "8.7.1"
   },
   "scripts": {
     "build": "rollup --config",
index 18c38580874727a909b49a89d1200c8d964d7728..7863d1ca9e8ba5e05c754444f634c1d0e39dc33c 100644 (file)
@@ -7,7 +7,7 @@
   "type": "module",
   "volta": {
     "node": "20.5.1",
-    "pnpm": "8.7.0"
+    "pnpm": "8.7.1"
   },
   "scripts": {
     "build": "rollup --config",
index bd5e622d823dcbcffe0e22542d222e1ee0cf45fa..557698e4ffd2ad2a16119e15401879549b25ef27 100644 (file)
@@ -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",
index 6322ff168cd398641e8f243d6914cb63f9cdd2c1..cd9e5e501178851bd76247898334a4254263bc59 100644 (file)
@@ -7,7 +7,7 @@
   "type": "module",
   "volta": {
     "node": "20.5.1",
-    "pnpm": "8.7.0"
+    "pnpm": "8.7.1"
   },
   "scripts": {
     "build": "rollup --config",
index b7ceda4ea9a9adc28c0d8fb48740aa45f8bc460d..57bf2bb4e5659224c309dc89ff857b238d14a0e7 100644 (file)
@@ -7,7 +7,7 @@
   "type": "module",
   "volta": {
     "node": "20.5.1",
-    "pnpm": "8.7.0"
+    "pnpm": "8.7.1"
   },
   "scripts": {
     "build": "rollup --config",
index 8914fc391da4e33fad7e283cd7ddc4bbfa097cef..3bd5c287b1397f8f0f950b450804e9599ab6ead6 100644 (file)
@@ -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",
index 3e15f2a5394fa3f63ee340b5f50770bba2700a6b..2e1b61b8652b88ad5149c05a5020530b28364946 100644 (file)
@@ -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",
index 96d24cd99a75c244944c8da2c58c42a830e463a2..cb0afd39bbf5f84ef1b13e5e4bd672b330880cd6 100644 (file)
@@ -7,7 +7,7 @@
   "type": "module",
   "volta": {
     "node": "20.5.1",
-    "pnpm": "8.7.0"
+    "pnpm": "8.7.1"
   },
   "scripts": {
     "build": "rollup --config",
index 952fae55cb9347eade4d1475115b955cebdf48cb..52a0cb1479963aeff1f20d5c8f73bf94ccb9a660 100644 (file)
@@ -7,7 +7,7 @@
   "type": "module",
   "volta": {
     "node": "20.5.1",
-    "pnpm": "8.7.0"
+    "pnpm": "8.7.1"
   },
   "scripts": {
     "build": "rollup --config",
index 3bc5ccd727b9e7bec8590cee31922799e4aca48f..db1e5029d7c424339668043d44da6d65d061756b 100644 (file)
@@ -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",
index d776fa1150e4ce440976a87a3c4194e198ab3602..fb6509c18d4ecc9444115cee8b1c66a1e2740736 100644 (file)
@@ -50,7 +50,7 @@
   },
   "volta": {
     "node": "20.5.1",
-    "pnpm": "8.7.0"
+    "pnpm": "8.7.1"
   },
   "repository": {
     "type": "git",
index 7075bc6cae778d8c9107d657eb61bcdf368a20db..a9632d87c86d91e64407219a42402f554cac8bed 100644 (file)
@@ -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
   }
index ca3d9b9d640fc6bf0faedfe3105d5751802281e1..3c41dd6ffee305c8eb2f51f593df022d8889745b 100644 (file)
@@ -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)
     }
   }
 
index daa1b4e73f67726d01b074c3064a65a5c0d06f6a..055a2dbb64e6257bef21221f709c2e0756b89d84 100644 (file)
@@ -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(