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 const numberOfWorkers = 4
11 const numberOfThreads = 4
12 let clusterFixedPool, threadFixedPool
14 before('Create pools', () => {
15 clusterFixedPool = new FixedClusterPool(
17 './tests/worker-files/cluster/testWorker.cjs'
19 threadFixedPool = new FixedThreadPool(
21 './tests/worker-files/thread/testWorker.mjs'
25 after('Destroy pools', async () => {
26 await clusterFixedPool.destroy()
27 await threadFixedPool.destroy()
30 it('Verify buildWorkerChoiceStrategyOptions() behavior', async () => {
31 expect(buildWorkerChoiceStrategyOptions(clusterFixedPool)).toStrictEqual({
32 elu: { median: false },
33 runTime: { median: false },
34 waitTime: { median: false },
35 weights: expect.objectContaining({
36 0: expect.any(Number),
37 [clusterFixedPool.info.maxSize - 1]: expect.any(Number),
40 const workerChoiceStrategyOptions = {
41 elu: { median: true },
42 runTime: { median: true },
43 waitTime: { median: true },
50 buildWorkerChoiceStrategyOptions(
52 workerChoiceStrategyOptions
54 ).toStrictEqual(workerChoiceStrategyOptions)
57 it('Verify getWorkerChoiceStrategyRetries() behavior', async () => {
58 expect(getWorkerChoiceStrategiesRetries(threadFixedPool)).toBe(
59 threadFixedPool.info.maxSize * 2
61 const workerChoiceStrategyOptions = {
62 elu: { median: true },
63 runTime: { median: true },
64 waitTime: { median: true },
71 getWorkerChoiceStrategiesRetries(
73 workerChoiceStrategyOptions
76 threadFixedPool.info.maxSize +
77 Object.keys(workerChoiceStrategyOptions.weights).length