+ { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
+ )
+ // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
+ const promises = []
+ 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(
+ // pool.workerChoiceStrategyContext.workerChoiceStrategy
+ // ).workerLastVirtualTaskTimestamp.size
+ // ).toBe(pool.workerNodes.length)
+ // }
+ // We need to clean up the resources after our test
+ await pool.destroy()
+ })
+
+ it('Verify FAIR_SHARE strategy internals are resets after setting it', async () => {
+ const workerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE
+ let pool = new FixedThreadPool(
+ max,
+ './tests/worker-files/thread/testWorker.js'
+ )
+ expect(
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).workerLastVirtualTaskTimestamp
+ ).toBeDefined()
+ pool.setWorkerChoiceStrategy(workerChoiceStrategy)
+ for (const workerNodeKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(pool.workerChoiceStrategyContext.workerChoiceStrategy)
+ .workerLastVirtualTaskTimestamp.keys()) {
+ expect(
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(pool.workerChoiceStrategyContext.workerChoiceStrategy)
+ .workerLastVirtualTaskTimestamp.get(workerNodeKey).start
+ ).toBe(0)
+ expect(
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(pool.workerChoiceStrategyContext.workerChoiceStrategy)
+ .workerLastVirtualTaskTimestamp.get(workerNodeKey).end
+ ).toBe(0)
+ }
+ await pool.destroy()
+ pool = new DynamicThreadPool(
+ min,
+ max,
+ './tests/worker-files/thread/testWorker.js'
+ )
+ expect(
+ pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).workerLastVirtualTaskTimestamp
+ ).toBeDefined()
+ pool.setWorkerChoiceStrategy(workerChoiceStrategy)
+ for (const workerNodeKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(pool.workerChoiceStrategyContext.workerChoiceStrategy)
+ .workerLastVirtualTaskTimestamp.keys()) {
+ expect(
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(pool.workerChoiceStrategyContext.workerChoiceStrategy)
+ .workerLastVirtualTaskTimestamp.get(workerNodeKey).start
+ ).toBe(0)
+ expect(
+ pool.workerChoiceStrategyContext.workerChoiceStrategies
+ .get(pool.workerChoiceStrategyContext.workerChoiceStrategy)
+ .workerLastVirtualTaskTimestamp.get(workerNodeKey).end
+ ).toBe(0)
+ }
+ // We need to clean up the resources after our test
+ await pool.destroy()
+ })
+
+ it('Verify WEIGHTED_ROUND_ROBIN strategy default tasks usage statistics requirements', async () => {
+ const workerChoiceStrategy = WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+ let pool = new FixedThreadPool(
+ max,
+ './tests/worker-files/thread/testWorker.js',
+ { workerChoiceStrategy }
+ )
+ 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,
+ max,
+ './tests/worker-files/thread/testWorker.js',
+ { workerChoiceStrategy }
+ )
+ 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()
+ })
+
+ it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a fixed pool', async () => {
+ const pool = new FixedThreadPool(
+ max,
+ './tests/worker-files/thread/testWorker.js',
+ { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }