perf: pre-instantiate worker choice strategies
[poolifier.git] / tests / pools / selection-strategies / selection-strategies.test.js
index b8341f09e9093566b28c672fd55a5cf107a966d3..591b2c4d772a227676c469e0a857f4d8ca3a1a1d 100644 (file)
@@ -2,7 +2,8 @@ const { expect } = require('expect')
 const {
   WorkerChoiceStrategies,
   DynamicThreadPool,
-  FixedThreadPool
+  FixedThreadPool,
+  FixedClusterPool
 } = require('../../../lib/index')
 
 describe('Selection strategies test suite', () => {
@@ -11,7 +12,8 @@ describe('Selection strategies test suite', () => {
 
   it('Verify that WorkerChoiceStrategies enumeration provides string values', () => {
     expect(WorkerChoiceStrategies.ROUND_ROBIN).toBe('ROUND_ROBIN')
-    expect(WorkerChoiceStrategies.LESS_RECENTLY_USED).toBe('LESS_RECENTLY_USED')
+    expect(WorkerChoiceStrategies.LESS_USED).toBe('LESS_USED')
+    expect(WorkerChoiceStrategies.LESS_BUSY).toBe('LESS_BUSY')
     expect(WorkerChoiceStrategies.FAIR_SHARE).toBe('FAIR_SHARE')
     expect(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN).toBe(
       'WEIGHTED_ROUND_ROBIN'
@@ -41,7 +43,9 @@ describe('Selection strategies test suite', () => {
       WorkerChoiceStrategies.ROUND_ROBIN
     )
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy().nextWorkerIndex
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.ROUND_ROBIN
+      ).nextWorkerId
     ).toBe(0)
     // We need to clean up the resources after our test
     await pool.destroy()
@@ -68,8 +72,10 @@ describe('Selection strategies test suite', () => {
     )
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN)
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .requiredStatistics.runTime
+      pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+    ).toBe(false)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
     ).toBe(false)
     await pool.destroy()
     pool = new DynamicThreadPool(
@@ -79,8 +85,10 @@ describe('Selection strategies test suite', () => {
     )
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN)
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .requiredStatistics.runTime
+      pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+    ).toBe(false)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
     ).toBe(false)
     // We need to clean up the resources after our test
     await pool.destroy()
@@ -125,6 +133,26 @@ describe('Selection strategies test suite', () => {
     await pool.destroy()
   })
 
+  it('Verify ROUND_ROBIN strategy runtime behavior', async () => {
+    let pool = new FixedClusterPool(
+      max,
+      './tests/worker-files/cluster/testWorker.js'
+    )
+    let results = new Set()
+    for (let i = 0; i < max; i++) {
+      results.add(pool.chooseWorker()[1].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)
+    }
+    expect(results.size).toBe(max)
+    await pool.destroy()
+  })
+
   it('Verify ROUND_ROBIN strategy internals are resets after setting it', async () => {
     let pool = new FixedThreadPool(
       max,
@@ -132,11 +160,15 @@ describe('Selection strategies test suite', () => {
       { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
     )
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy().nextWorkerIndex
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.ROUND_ROBIN
+      ).nextWorkerId
+    ).toBeDefined()
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN)
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy().nextWorkerIndex
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.ROUND_ROBIN
+      ).nextWorkerId
     ).toBe(0)
     await pool.destroy()
     pool = new DynamicThreadPool(
@@ -146,53 +178,57 @@ describe('Selection strategies test suite', () => {
       { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
     )
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .workerChoiceStrategy.nextWorkerIndex
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.ROUND_ROBIN
+      ).nextWorkerId
+    ).toBeDefined()
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.ROUND_ROBIN)
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .workerChoiceStrategy.nextWorkerIndex
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.ROUND_ROBIN
+      ).nextWorkerId
     ).toBe(0)
     // We need to clean up the resources after our test
     await pool.destroy()
   })
 
-  it('Verify LESS_RECENTLY_USED strategy is taken at pool creation', async () => {
+  it('Verify LESS_USED strategy is taken at pool creation', async () => {
     const pool = new FixedThreadPool(
       max,
       './tests/worker-files/thread/testWorker.js',
-      { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED }
+      { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
     )
     expect(pool.opts.workerChoiceStrategy).toBe(
-      WorkerChoiceStrategies.LESS_RECENTLY_USED
+      WorkerChoiceStrategies.LESS_USED
     )
     // We need to clean up the resources after our test
     await pool.destroy()
   })
 
-  it('Verify LESS_RECENTLY_USED strategy can be set after pool creation', async () => {
+  it('Verify LESS_USED strategy can be set after pool creation', async () => {
     const pool = new FixedThreadPool(
       max,
       './tests/worker-files/thread/testWorker.js'
     )
-    pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_RECENTLY_USED)
+    pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_USED)
     expect(pool.opts.workerChoiceStrategy).toBe(
-      WorkerChoiceStrategies.LESS_RECENTLY_USED
+      WorkerChoiceStrategies.LESS_USED
     )
     // We need to clean up the resources after our test
     await pool.destroy()
   })
 
-  it('Verify LESS_RECENTLY_USED strategy default tasks usage statistics requirements', async () => {
+  it('Verify LESS_USED strategy default tasks usage statistics requirements', async () => {
     let pool = new FixedThreadPool(
       max,
       './tests/worker-files/thread/testWorker.js'
     )
-    pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_RECENTLY_USED)
+    pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_USED)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+    ).toBe(false)
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .requiredStatistics.runTime
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
     ).toBe(false)
     await pool.destroy()
     pool = new DynamicThreadPool(
@@ -200,22 +236,24 @@ describe('Selection strategies test suite', () => {
       max,
       './tests/worker-files/thread/testWorker.js'
     )
-    pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_RECENTLY_USED)
+    pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_USED)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+    ).toBe(false)
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .requiredStatistics.runTime
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
     ).toBe(false)
     // We need to clean up the resources after our test
     await pool.destroy()
   })
 
-  it('Verify LESS_RECENTLY_USED strategy can be run in a fixed pool', async () => {
+  it('Verify LESS_USED strategy can be run in a fixed pool', async () => {
     const pool = new FixedThreadPool(
       max,
       './tests/worker-files/thread/testWorker.js',
-      { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED }
+      { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
     )
-    // TODO: Create a better test to cover `LessRecentlyUsedWorkerChoiceStrategy#choose`
+    // TODO: Create a better test to cover `LessUsedWorkerChoiceStrategy#choose`
     const promises = []
     for (let i = 0; i < max * 2; i++) {
       promises.push(pool.execute())
@@ -225,14 +263,102 @@ describe('Selection strategies test suite', () => {
     await pool.destroy()
   })
 
-  it('Verify LESS_RECENTLY_USED strategy can be run in a dynamic pool', async () => {
+  it('Verify LESS_USED strategy can be run in a dynamic pool', async () => {
     const pool = new DynamicThreadPool(
       min,
       max,
       './tests/worker-files/thread/testWorker.js',
-      { workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED }
+      { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED }
     )
-    // TODO: Create a better test to cover `LessRecentlyUsedWorkerChoiceStrategy#choose`
+    // TODO: Create a better test to cover `LessUsedWorkerChoiceStrategy#choose`
+    const promises = []
+    for (let i = 0; i < max * 2; i++) {
+      promises.push(pool.execute())
+    }
+    await Promise.all(promises)
+    // We need to clean up the resources after our test
+    await pool.destroy()
+  })
+
+  it('Verify LESS_BUSY strategy is taken at pool creation', async () => {
+    const pool = new FixedThreadPool(
+      max,
+      './tests/worker-files/thread/testWorker.js',
+      { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY }
+    )
+    expect(pool.opts.workerChoiceStrategy).toBe(
+      WorkerChoiceStrategies.LESS_BUSY
+    )
+    // We need to clean up the resources after our test
+    await pool.destroy()
+  })
+
+  it('Verify LESS_BUSY strategy can be set after pool creation', async () => {
+    const pool = new FixedThreadPool(
+      max,
+      './tests/worker-files/thread/testWorker.js'
+    )
+    pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_BUSY)
+    expect(pool.opts.workerChoiceStrategy).toBe(
+      WorkerChoiceStrategies.LESS_BUSY
+    )
+    // We need to clean up the resources after our test
+    await pool.destroy()
+  })
+
+  it('Verify LESS_BUSY strategy default tasks usage statistics requirements', async () => {
+    let pool = new FixedThreadPool(
+      max,
+      './tests/worker-files/thread/testWorker.js'
+    )
+    pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_BUSY)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+    ).toBe(true)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
+    ).toBe(false)
+    await pool.destroy()
+    pool = new DynamicThreadPool(
+      min,
+      max,
+      './tests/worker-files/thread/testWorker.js'
+    )
+    pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.LESS_BUSY)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+    ).toBe(true)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
+    ).toBe(false)
+    // We need to clean up the resources after our test
+    await pool.destroy()
+  })
+
+  it('Verify LESS_BUSY strategy can be run in a fixed pool', async () => {
+    const pool = new FixedThreadPool(
+      max,
+      './tests/worker-files/thread/testWorker.js',
+      { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY }
+    )
+    // TODO: Create a better test to cover `LessBusyWorkerChoiceStrategy#choose`
+    const promises = []
+    for (let i = 0; i < max * 2; i++) {
+      promises.push(pool.execute())
+    }
+    await Promise.all(promises)
+    // We need to clean up the resources after our test
+    await pool.destroy()
+  })
+
+  it('Verify LESS_BUSY strategy can be run in a dynamic pool', async () => {
+    const pool = new DynamicThreadPool(
+      min,
+      max,
+      './tests/worker-files/thread/testWorker.js',
+      { workerChoiceStrategy: WorkerChoiceStrategies.LESS_BUSY }
+    )
+    // TODO: Create a better test to cover `LessBusyWorkerChoiceStrategy#choose`
     const promises = []
     for (let i = 0; i < max * 2; i++) {
       promises.push(pool.execute())
@@ -251,18 +377,18 @@ describe('Selection strategies test suite', () => {
     expect(pool.opts.workerChoiceStrategy).toBe(
       WorkerChoiceStrategies.FAIR_SHARE
     )
-    for (const worker of pool.workerChoiceStrategyContext
-      .getWorkerChoiceStrategy()
+    for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+      .get(WorkerChoiceStrategies.FAIR_SHARE)
       .workerLastVirtualTaskTimestamp.keys()) {
       expect(
-        pool.workerChoiceStrategyContext
-          .getWorkerChoiceStrategy()
-          .workerLastVirtualTaskTimestamp.get(worker).start
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.FAIR_SHARE)
+          .workerLastVirtualTaskTimestamp.get(workerKey).start
       ).toBe(0)
       expect(
-        pool.workerChoiceStrategyContext
-          .getWorkerChoiceStrategy()
-          .workerLastVirtualTaskTimestamp.get(worker).end
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.FAIR_SHARE)
+          .workerLastVirtualTaskTimestamp.get(workerKey).end
       ).toBe(0)
     }
     // We need to clean up the resources after our test
@@ -289,8 +415,10 @@ describe('Selection strategies test suite', () => {
     )
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .requiredStatistics.runTime
+      pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+    ).toBe(true)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
     ).toBe(true)
     await pool.destroy()
     pool = new DynamicThreadPool(
@@ -300,8 +428,10 @@ describe('Selection strategies test suite', () => {
     )
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .requiredStatistics.runTime
+      pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+    ).toBe(true)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
     ).toBe(true)
     // We need to clean up the resources after our test
     await pool.destroy()
@@ -319,6 +449,11 @@ describe('Selection strategies test suite', () => {
       promises.push(pool.execute())
     }
     await Promise.all(promises)
+    expect(
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.FAIR_SHARE
+      ).workerLastVirtualTaskTimestamp.size
+    ).toBe(pool.workers.length)
     // We need to clean up the resources after our test
     await pool.destroy()
   })
@@ -332,10 +467,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)
+    // if (process.platform !== 'win32') {
+    //   expect(
+    //     pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+    //       WorkerChoiceStrategies.FAIR_SHARE
+    //     ).workerLastVirtualTaskTimestamp.size
+    //   ).toBe(pool.workers.length)
+    // }
     // We need to clean up the resources after our test
     await pool.destroy()
   })
@@ -346,22 +489,23 @@ describe('Selection strategies test suite', () => {
       './tests/worker-files/thread/testWorker.js'
     )
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .workerLastVirtualTaskTimestamp
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.FAIR_SHARE
+      ).workerLastVirtualTaskTimestamp
+    ).toBeDefined()
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
-    for (const worker of pool.workerChoiceStrategyContext
-      .getWorkerChoiceStrategy()
+    for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+      .get(WorkerChoiceStrategies.FAIR_SHARE)
       .workerLastVirtualTaskTimestamp.keys()) {
       expect(
-        pool.workerChoiceStrategyContext
-          .getWorkerChoiceStrategy()
-          .workerLastVirtualTaskTimestamp.get(worker).start
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.FAIR_SHARE)
+          .workerLastVirtualTaskTimestamp.get(workerKey).start
       ).toBe(0)
       expect(
-        pool.workerChoiceStrategyContext
-          .getWorkerChoiceStrategy()
-          .workerLastVirtualTaskTimestamp.get(worker).end
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.FAIR_SHARE)
+          .workerLastVirtualTaskTimestamp.get(workerKey).end
       ).toBe(0)
     }
     await pool.destroy()
@@ -371,22 +515,23 @@ describe('Selection strategies test suite', () => {
       './tests/worker-files/thread/testWorker.js'
     )
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .workerChoiceStrategy.workerLastVirtualTaskTimestamp
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.FAIR_SHARE
+      ).workerLastVirtualTaskTimestamp
+    ).toBeDefined()
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
-    for (const worker of pool.workerChoiceStrategyContext
-      .getWorkerChoiceStrategy()
-      .workerChoiceStrategy.workerLastVirtualTaskTimestamp.keys()) {
+    for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+      .get(WorkerChoiceStrategies.FAIR_SHARE)
+      .workerLastVirtualTaskTimestamp.keys()) {
       expect(
-        pool.workerChoiceStrategyContext
-          .getWorkerChoiceStrategy()
-          .workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(worker).start
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.FAIR_SHARE)
+          .workerLastVirtualTaskTimestamp.get(workerKey).start
       ).toBe(0)
       expect(
-        pool.workerChoiceStrategyContext
-          .getWorkerChoiceStrategy()
-          .workerChoiceStrategy.workerLastVirtualTaskTimestamp.get(worker).end
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.FAIR_SHARE)
+          .workerLastVirtualTaskTimestamp.get(workerKey).end
       ).toBe(0)
     }
     // We need to clean up the resources after our test
@@ -403,25 +548,27 @@ describe('Selection strategies test suite', () => {
       WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
     )
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .currentWorkerIndex
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).currentWorkerId
     ).toBe(0)
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .defaultWorkerWeight
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).defaultWorkerWeight
     ).toBeGreaterThan(0)
-    for (const worker of pool.workerChoiceStrategyContext
-      .getWorkerChoiceStrategy()
+    for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+      .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
       .workersTaskRunTime.keys()) {
       expect(
-        pool.workerChoiceStrategyContext
-          .getWorkerChoiceStrategy()
-          .workersTaskRunTime.get(worker).weight
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+          .workersTaskRunTime.get(workerKey).weight
       ).toBeGreaterThan(0)
       expect(
-        pool.workerChoiceStrategyContext
-          .getWorkerChoiceStrategy()
-          .workersTaskRunTime.get(worker).runTime
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+          .workersTaskRunTime.get(workerKey).runTime
       ).toBe(0)
     }
     // We need to clean up the resources after our test
@@ -448,8 +595,10 @@ describe('Selection strategies test suite', () => {
     )
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .requiredStatistics.runTime
+      pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+    ).toBe(true)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
     ).toBe(true)
     await pool.destroy()
     pool = new DynamicThreadPool(
@@ -459,8 +608,10 @@ describe('Selection strategies test suite', () => {
     )
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .requiredStatistics.runTime
+      pool.workerChoiceStrategyContext.getRequiredStatistics().runTime
+    ).toBe(true)
+    expect(
+      pool.workerChoiceStrategyContext.getRequiredStatistics().avgRunTime
     ).toBe(true)
     // We need to clean up the resources after our test
     await pool.destroy()
@@ -478,6 +629,11 @@ describe('Selection strategies test suite', () => {
       promises.push(pool.execute())
     }
     await Promise.all(promises)
+    expect(
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).workersTaskRunTime.size
+    ).toBe(pool.workers.length)
     // We need to clean up the resources after our test
     await pool.destroy()
   })
@@ -491,10 +647,21 @@ describe('Selection strategies test suite', () => {
     )
     // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
     const promises = []
-    for (let i = 0; i < max * 2; i++) {
+    const maxMultiplier =
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).defaultWorkerWeight * 2
+    for (let i = 0; i < max * maxMultiplier; i++) {
       promises.push(pool.execute())
     }
     await Promise.all(promises)
+    if (process.platform !== 'win32') {
+      expect(
+        pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+          WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+        ).workersTaskRunTime.size
+      ).toBe(pool.workers.length)
+    }
     // We need to clean up the resources after our test
     await pool.destroy()
   })
@@ -505,33 +672,38 @@ describe('Selection strategies test suite', () => {
       './tests/worker-files/thread/testWorker.js'
     )
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .currentWorkerIndex
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).currentWorkerId
+    ).toBeDefined()
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .defaultWorkerWeight
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).defaultWorkerWeight
+    ).toBeDefined()
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .workersTaskRunTime
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).workersTaskRunTime
+    ).toBeDefined()
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .currentWorkerIndex
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).currentWorkerId
     ).toBe(0)
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .defaultWorkerWeight
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).defaultWorkerWeight
     ).toBeGreaterThan(0)
-    for (const worker of pool.workerChoiceStrategyContext
-      .getWorkerChoiceStrategy()
+    for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+      .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
       .workersTaskRunTime.keys()) {
       expect(
-        pool.workerChoiceStrategyContext
-          .getWorkerChoiceStrategy()
-          .workersTaskRunTime.get(worker).runTime
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+          .workersTaskRunTime.get(workerKey).runTime
       ).toBe(0)
     }
     await pool.destroy()
@@ -541,33 +713,38 @@ describe('Selection strategies test suite', () => {
       './tests/worker-files/thread/testWorker.js'
     )
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .workerChoiceStrategy.currentWorkerIndex
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).currentWorkerId
+    ).toBeDefined()
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .workerChoiceStrategy.defaultWorkerWeight
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).defaultWorkerWeight
+    ).toBeDefined()
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .workerChoiceStrategy.workersTaskRunTime
-    ).toBeUndefined()
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).workersTaskRunTime
+    ).toBeDefined()
     pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .workerChoiceStrategy.currentWorkerIndex
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).currentWorkerId
     ).toBe(0)
     expect(
-      pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
-        .workerChoiceStrategy.defaultWorkerWeight
+      pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+        WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+      ).defaultWorkerWeight
     ).toBeGreaterThan(0)
-    for (const worker of pool.workerChoiceStrategyContext
-      .getWorkerChoiceStrategy()
-      .workerChoiceStrategy.workersTaskRunTime.keys()) {
+    for (const workerKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+      .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+      .workersTaskRunTime.keys()) {
       expect(
-        pool.workerChoiceStrategyContext
-          .getWorkerChoiceStrategy()
-          .workerChoiceStrategy.workersTaskRunTime.get(worker).runTime
+        pool.workerChoiceStrategyContext.workerChoiceStrategies
+          .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
+          .workersTaskRunTime.get(workerKey).runTime
       ).toBe(0)
     }
     // We need to clean up the resources after our test
@@ -584,7 +761,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'")
     )
   })
 })