- it('Verify WEIGHTED_ROUND_ROBIN strategy is taken at pool creation', async () => {
- const pool = new FixedThreadPool(
- max,
- './tests/worker-files/thread/testWorker.js',
- { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
- )
- expect(pool.opts.workerChoiceStrategy).toBe(
- WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
- )
- expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy().currentWorkerId
- ).toBe(0)
- expect(
- pool.workerChoiceStrategyContext.getWorkerChoiceStrategy()
- .defaultWorkerWeight
- ).toBeGreaterThan(0)
- for (const workerKey of pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workersTaskRunTime.keys()) {
- expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workersTaskRunTime.get(workerKey).weight
- ).toBeGreaterThan(0)
- expect(
- pool.workerChoiceStrategyContext
- .getWorkerChoiceStrategy()
- .workersTaskRunTime.get(workerKey).runTime
- ).toBe(0)
- }
- // We need to clean up the resources after our test
- await pool.destroy()
- })
-
- it('Verify WEIGHTED_ROUND_ROBIN strategy can be set after pool creation', async () => {
- const pool = new FixedThreadPool(
- max,
- './tests/worker-files/thread/testWorker.js'
- )
- pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
- expect(pool.opts.workerChoiceStrategy).toBe(
- WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
- )
- // We need to clean up the resources after our test
- await pool.destroy()
- })
-