- 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.workerChoiceStrategies.get(
- WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
- ).currentWorkerNodeId
- ).toBe(0)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
- for (const workerNodeKey of pool.workerChoiceStrategyContext.workerChoiceStrategies
- .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
- .workersTaskRunTime.keys()) {
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies
- .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
- .workersTaskRunTime.get(workerNodeKey).weight
- ).toBeGreaterThan(0)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies
- .get(WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN)
- .workersTaskRunTime.get(workerNodeKey).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()
- })
-