1 import { expect } from 'expect'
3 import { FixedClusterPool, FixedThreadPool } from '../../../lib/index.cjs'
5 buildWorkerChoiceStrategyOptions,
6 getWorkerChoiceStrategiesRetries,
7 } from '../../../lib/pools/selection-strategies/selection-strategies-utils.cjs'
9 describe('Selection strategies utils test suite', () => {
10 it('Verify buildWorkerChoiceStrategyOptions() behavior', async () => {
11 const numberOfWorkers = 4
12 const pool = new FixedClusterPool(
14 './tests/worker-files/cluster/testWorker.cjs'
16 expect(buildWorkerChoiceStrategyOptions(pool)).toStrictEqual({
17 runTime: { median: false },
18 waitTime: { median: false },
19 elu: { median: false },
20 weights: expect.objectContaining({
21 0: expect.any(Number),
22 [pool.info.maxSize - 1]: expect.any(Number),
25 const workerChoiceStrategyOptions = {
26 runTime: { median: true },
27 waitTime: { median: true },
28 elu: { median: true },
35 buildWorkerChoiceStrategyOptions(pool, workerChoiceStrategyOptions)
36 ).toStrictEqual(workerChoiceStrategyOptions)
40 it('Verify getWorkerChoiceStrategyRetries() behavior', async () => {
41 const numberOfThreads = 4
42 const pool = new FixedThreadPool(
44 './tests/worker-files/thread/testWorker.mjs'
46 expect(getWorkerChoiceStrategiesRetries(pool)).toBe(pool.info.maxSize * 2)
47 const workerChoiceStrategyOptions = {
48 runTime: { median: true },
49 waitTime: { median: true },
50 elu: { median: true },
57 getWorkerChoiceStrategiesRetries(pool, workerChoiceStrategyOptions)
60 Object.keys(workerChoiceStrategyOptions.weights).length