feat: add pool option to enable median runtime
[poolifier.git] / tests / pools / selection-strategies / selection-strategies.test.js
index dd420c7f89b04f86792af87850d85dcbffe4f0d8..2fff1b13772e43c4acad99ad48e7441fda474dee 100644 (file)
@@ -43,7 +43,9 @@ describe('Selection strategies test suite', () => {
       WorkerChoiceStrategies.ROUND_ROBIN
     )
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.nextWorkerId
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.ROUND_ROBIN
+      ).nextWorkerNodeId
     ).toBe(0)
     // We need to clean up the resources after our test
     await pool.destroy()
@@ -72,6 +74,12 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
     ).toBe(false)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
+    ).toBe(false)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+    ).toBe(false)
     await pool.destroy()
     pool = new DynamicThreadPool(
       min,
@@ -82,6 +90,12 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
     ).toBe(false)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
+    ).toBe(false)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+    ).toBe(false)
     // We need to clean up the resources after our test
     await pool.destroy()
   })
@@ -132,14 +146,14 @@ describe('Selection strategies test suite', () => {
     )
     let results = new Set()
     for (let i = 0; i < max; i++) {
-      results.add(pool.chooseWorker()[1].id)
+      results.add(pool.chooseWorkerNode()[1].worker.id)
     }
     expect(results.size).toBe(max)
     await pool.destroy()
     pool = new FixedThreadPool(max, './tests/worker-files/thread/testWorker.js')
     results = new Set()
     for (let i = 0; i < max; i++) {
-      results.add(pool.chooseWorker()[1].threadId)
+      results.add(pool.chooseWorkerNode()[1].worker.threadId)
     }
     expect(results.size).toBe(max)
     await pool.destroy()
@@ -152,11 +166,15 @@ describe('Selection strategies test suite', () => {
       { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
     )
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.nextWorkerId
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.ROUND_ROBIN
+      ).nextWorkerNodeId
+    ).toBeDefined()
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN)
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.nextWorkerId
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.ROUND_ROBIN
+      ).nextWorkerNodeId
     ).toBe(0)
     await pool.destroy()
     pool = new DynamicThreadPool(
@@ -166,13 +184,15 @@ describe('Selection strategies test suite', () => {
       { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
     )
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
-        .nextWorkerId
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.ROUND_ROBIN
+      ).nextWorkerNodeId
+    ).toBeDefined()
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN)
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
-        .nextWorkerId
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.ROUND_ROBIN
+      ).nextWorkerNodeId
     ).toBe(0)
     // We need to clean up the resources after our test
     await pool.destroy()
@@ -213,6 +233,12 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
     ).toBe(false)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
+    ).toBe(false)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+    ).toBe(false)
     await pool.destroy()
     pool = new DynamicThreadPool(
       min,
@@ -223,6 +249,12 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
     ).toBe(false)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
+    ).toBe(false)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+    ).toBe(false)
     // We need to clean up the resources after our test
     await pool.destroy()
   })
@@ -295,6 +327,12 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
     ).toBe(true)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
+    ).toBe(false)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+    ).toBe(false)
     await pool.destroy()
     pool = new DynamicThreadPool(
       min,
@@ -305,6 +343,12 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
     ).toBe(true)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
+    ).toBe(false)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+    ).toBe(false)
     // We need to clean up the resources after our test
     await pool.destroy()
   })
@@ -351,16 +395,18 @@ describe('Selection strategies test suite', () => {
     expect(pool.opts.workerChoiceStrategy).toBe(
       WorkerChoiceStrategies.FAIR_SHARE
     )
-    for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) {
+    for (const workerNodeKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+      .get(WorkerChoiceStrategies.FAIR_SHARE)
+      .workerLastVirtualTaskTimestamp.keys()) {
       expect(
-        pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
-          workerKey
-        ).start
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.FAIR_SHARE)
+          .workerLastVirtualTaskTimestamp.get(workerNodeKey).start
       ).toBe(0)
       expect(
-        pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
-          workerKey
-        ).end
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.FAIR_SHARE)
+          .workerLastVirtualTaskTimestamp.get(workerNodeKey).end
       ).toBe(0)
     }
     // We need to clean up the resources after our test
@@ -389,6 +435,12 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
     ).toBe(true)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
+    ).toBe(true)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+    ).toBe(false)
     await pool.destroy()
     pool = new DynamicThreadPool(
       min,
@@ -399,6 +451,12 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
     ).toBe(true)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
+    ).toBe(true)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+    ).toBe(false)
     // We need to clean up the resources after our test
     await pool.destroy()
   })
@@ -416,9 +474,10 @@ describe('Selection strategies test suite', () => {
     }
     await Promise.all(promises)
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy
-        .workerLastVirtualTaskTimestamp.size
-    ).toBe(pool.workers.length)
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.FAIR_SHARE
+      ).workerLastVirtualTaskTimestamp.size
+    ).toBe(pool.workerNodes.length)
     // We need to clean up the resources after our test
     await pool.destroy()
   })
@@ -432,14 +491,18 @@ describe('Selection strategies test suite', () => {
     )
     // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
     const promises = []
-    for (let i = 0; i < max * 2; i++) {
+    const maxMultiplier = 2
+    for (let i = 0; i < max * maxMultiplier; i++) {
       promises.push(pool.execute())
     }
     await Promise.all(promises)
-    expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
-        .workerLastVirtualTaskTimestamp.size
-    ).toBe(pool.workers.length)
+    // if (process.platform !== 'win32') {
+    //   expect(
+    //     pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+    //       WorkerChoiceStrategies.FAIR_SHARE
+    //     ).workerLastVirtualTaskTimestamp.size
+    //   ).toBe(pool.workerNodes.length)
+    // }
     // We need to clean up the resources after our test
     await pool.destroy()
   })
@@ -450,20 +513,23 @@ describe('Selection strategies test suite', () => {
       './tests/worker-files/thread/testWorker.js'
     )
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy
-        .workerLastVirtualTaskTimestamp
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.FAIR_SHARE
+      ).workerLastVirtualTaskTimestamp
+    ).toBeDefined()
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
-    for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) {
+    for (const workerNodeKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+      .get(WorkerChoiceStrategies.FAIR_SHARE)
+      .workerLastVirtualTaskTimestamp.keys()) {
       expect(
-        pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
-          workerKey
-        ).start
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.FAIR_SHARE)
+          .workerLastVirtualTaskTimestamp.get(workerNodeKey).start
       ).toBe(0)
       expect(
-        pool.workerChoiceStrategyContext.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
-          workerKey
-        ).end
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.FAIR_SHARE)
+          .workerLastVirtualTaskTimestamp.get(workerNodeKey).end
       ).toBe(0)
     }
     await pool.destroy()
@@ -473,20 +539,23 @@ describe('Selection strategies test suite', () => {
       './tests/worker-files/thread/testWorker.js'
     )
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
-        .workerLastVirtualTaskTimestamp
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.FAIR_SHARE
+      ).workerLastVirtualTaskTimestamp
+    ).toBeDefined()
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
-    for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) {
+    for (const workerNodeKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+      .get(WorkerChoiceStrategies.FAIR_SHARE)
+      .workerLastVirtualTaskTimestamp.keys()) {
       expect(
-        pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
-          workerKey
-        ).start
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.FAIR_SHARE)
+          .workerLastVirtualTaskTimestamp.get(workerNodeKey).start
       ).toBe(0)
       expect(
-        pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(
-          workerKey
-        ).end
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.FAIR_SHARE)
+          .workerLastVirtualTaskTimestamp.get(workerNodeKey).end
       ).toBe(0)
     }
     // We need to clean up the resources after our test
@@ -503,21 +572,27 @@ describe('Selection strategies test suite', () => {
       WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
     )
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.currentWorkerId
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).currentWorkerNodeId
     ).toBe(0)
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.defaultWorkerWeight
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).defaultWorkerWeight
     ).toBeGreaterThan(0)
-    for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.keys()) {
+    for (const workerNodeKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+      .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+      .workersTaskRunTime.keys()) {
       expect(
-        pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.get(
-          workerKey
-        ).weight
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+          .workersTaskRunTime.get(workerNodeKey).weight
       ).toBeGreaterThan(0)
       expect(
-        pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.get(
-          workerKey
-        ).runTime
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+          .workersTaskRunTime.get(workerNodeKey).runTime
       ).toBe(0)
     }
     // We need to clean up the resources after our test
@@ -546,6 +621,12 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
     ).toBe(true)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
+    ).toBe(true)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+    ).toBe(false)
     await pool.destroy()
     pool = new DynamicThreadPool(
       min,
@@ -556,6 +637,12 @@ describe('Selection strategies test suite', () => {
     expect(
       pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
     ).toBe(true)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
+    ).toBe(true)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().medRunTime
+    ).toBe(false)
     // We need to clean up the resources after our test
     await pool.destroy()
   })
@@ -573,9 +660,10 @@ describe('Selection strategies test suite', () => {
     }
     await Promise.all(promises)
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime
-        .size
-    ).toBe(pool.workers.length)
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).workersTaskRunTime.size
+    ).toBe(pool.workerNodes.length)
     // We need to clean up the resources after our test
     await pool.destroy()
   })
@@ -590,16 +678,20 @@ describe('Selection strategies test suite', () => {
     // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
     const promises = []
     const maxMultiplier =
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
-        .defaultWorkerWeight
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).defaultWorkerWeight * 50
     for (let i = 0; i < max * maxMultiplier; i++) {
       promises.push(pool.execute())
     }
     await Promise.all(promises)
-    expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
-        .workersTaskRunTime.size
-    ).toBe(pool.workers.length)
+    if (process.platform !== 'win32') {
+      expect(
+        pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+          WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+        ).workersTaskRunTime.size
+      ).toBe(pool.workerNodes.length)
+    }
     // We need to clean up the resources after our test
     await pool.destroy()
   })
@@ -610,26 +702,38 @@ describe('Selection strategies test suite', () => {
       './tests/worker-files/thread/testWorker.js'
     )
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.currentWorkerId
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).currentWorkerNodeId
+    ).toBeDefined()
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.defaultWorkerWeight
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).defaultWorkerWeight
+    ).toBeDefined()
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).workersTaskRunTime
+    ).toBeDefined()
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.currentWorkerId
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).currentWorkerNodeId
     ).toBe(0)
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.defaultWorkerWeight
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).defaultWorkerWeight
     ).toBeGreaterThan(0)
-    for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.keys()) {
+    for (const workerNodeKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+      .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+      .workersTaskRunTime.keys()) {
       expect(
-        pool.workerChoiceStrategyContext.workerChoiceStrategy.workersTaskRunTime.get(
-          workerKey
-        ).runTime
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+          .workersTaskRunTime.get(workerNodeKey).runTime
       ).toBe(0)
     }
     await pool.destroy()
@@ -639,31 +743,38 @@ describe('Selection strategies test suite', () => {
       './tests/worker-files/thread/testWorker.js'
     )
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
-        .currentWorkerId
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).currentWorkerNodeId
+    ).toBeDefined()
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
-        .defaultWorkerWeight
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).defaultWorkerWeight
+    ).toBeDefined()
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
-        .workersTaskRunTime
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).workersTaskRunTime
+    ).toBeDefined()
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
-        .currentWorkerId
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).currentWorkerNodeId
     ).toBe(0)
     expect(
-      pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy
-        .defaultWorkerWeight
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).defaultWorkerWeight
     ).toBeGreaterThan(0)
-    for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workersTaskRunTime.keys()) {
+    for (const workerNodeKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+      .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+      .workersTaskRunTime.keys()) {
       expect(
-        pool.workerChoiceStrategyContext.workerChoiceStrategy.workerChoiceStrategy.workersTaskRunTime.get(
-          workerKey
-        ).runTime
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+          .workersTaskRunTime.get(workerNodeKey).runTime
       ).toBe(0)
     }
     // We need to clean up the resources after our test
@@ -680,7 +791,7 @@ describe('Selection strategies test suite', () => {
           { workerChoiceStrategy: 'UNKNOWN_STRATEGY' }
         )
     ).toThrowError(
-      new Error("Worker choice strategy 'UNKNOWN_STRATEGY' not found")
+      new Error("Invalid worker choice strategy 'UNKNOWN_STRATEGY'")
     )
   })
 })