test: improve WCS coverage
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 31 Aug 2023 14:26:03 +0000 (16:26 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Thu, 31 Aug 2023 14:26:03 +0000 (16:26 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
tests/pools/selection-strategies/selection-strategies.test.js
tests/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.test.js

index 6cc68a8b3cd58f26ff4911bcd9c0100de981a715..b396fba2a083b2fcad15c4f359ebdb848188f6d0 100644 (file)
@@ -113,13 +113,17 @@ describe('Selection strategies test suite', () => {
       './tests/worker-files/thread/testWorker.js'
     )
     for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) {
-      if (workerChoiceStrategy === WorkerChoiceStrategies.ROUND_ROBIN) {
-        expect(
-          pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
-            workerChoiceStrategy
-          ).nextWorkerNodeKey
-        ).toBe(0)
-      } else if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) {
+      expect(
+        pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+          workerChoiceStrategy
+        ).nextWorkerNodeKey
+      ).toBe(0)
+      expect(
+        pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+          workerChoiceStrategy
+        ).previousWorkerNodeKey
+      ).toBe(0)
+      if (workerChoiceStrategy === WorkerChoiceStrategies.FAIR_SHARE) {
         expect(
           pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
             workerChoiceStrategy
@@ -136,8 +140,17 @@ describe('Selection strategies test suite', () => {
         expect(
           pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
             workerChoiceStrategy
-          ).nextWorkerNodeKey
+          ).defaultWorkerWeight
+        ).toBeGreaterThan(0)
+        expect(
+          pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+            workerChoiceStrategy
+          ).workerVirtualTaskRunTime
         ).toBe(0)
+      } else if (
+        workerChoiceStrategy ===
+        WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN
+      ) {
         expect(
           pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
             workerChoiceStrategy
@@ -148,6 +161,25 @@ describe('Selection strategies test suite', () => {
             workerChoiceStrategy
           ).workerVirtualTaskRunTime
         ).toBe(0)
+        expect(
+          pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+            workerChoiceStrategy
+          ).roundId
+        ).toBe(0)
+        expect(
+          pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+            workerChoiceStrategy
+          ).workerNodeId
+        ).toBe(0)
+        expect(
+          pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+            workerChoiceStrategy
+          ).roundWeights
+        ).toStrictEqual([
+          pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+            workerChoiceStrategy
+          ).defaultWorkerWeight
+        ])
       }
     }
     await pool.destroy()
index e9de670a8a67edcad5dd72118ab4c80de9af686d..13722cb3144f05e42bfdc7aa1bf0fd68179612b9 100644 (file)
@@ -33,6 +33,7 @@ describe('Weighted round robin strategy worker choice strategy test suite', () =
     const resetResult = strategy.reset()
     expect(resetResult).toBe(true)
     expect(strategy.nextWorkerNodeKey).toBe(0)
+    expect(strategy.previousWorkerNodeKey).toBe(0)
     expect(strategy.workerVirtualTaskRunTime).toBe(0)
   })
 })