} from '../../../lib/pools/selection-strategies/selection-strategies-utils.cjs'
describe('Selection strategies utils test suite', () => {
- it('Verify buildWorkerChoiceStrategyOptions() behavior', async () => {
- const numberOfWorkers = 4
- const pool = new FixedClusterPool(
+ const numberOfWorkers = 4
+ const numberOfThreads = 4
+ let clusterFixedPool, threadFixedPool
+
+ before('Create pools', () => {
+ clusterFixedPool = new FixedClusterPool(
numberOfWorkers,
'./tests/worker-files/cluster/testWorker.cjs'
)
- expect(buildWorkerChoiceStrategyOptions(pool)).toStrictEqual({
+ threadFixedPool = new FixedThreadPool(
+ numberOfThreads,
+ './tests/worker-files/thread/testWorker.mjs'
+ )
+ })
+
+ after('Destroy pools', async () => {
+ await clusterFixedPool.destroy()
+ await threadFixedPool.destroy()
+ })
+
+ it('Verify buildWorkerChoiceStrategyOptions() behavior', async () => {
+ expect(buildWorkerChoiceStrategyOptions(clusterFixedPool)).toStrictEqual({
runTime: { median: false },
waitTime: { median: false },
elu: { median: false },
weights: expect.objectContaining({
0: expect.any(Number),
- [pool.info.maxSize - 1]: expect.any(Number),
+ [clusterFixedPool.info.maxSize - 1]: expect.any(Number),
}),
})
const workerChoiceStrategyOptions = {
},
}
expect(
- buildWorkerChoiceStrategyOptions(pool, workerChoiceStrategyOptions)
+ buildWorkerChoiceStrategyOptions(
+ clusterFixedPool,
+ workerChoiceStrategyOptions
+ )
).toStrictEqual(workerChoiceStrategyOptions)
- await pool.destroy()
})
it('Verify getWorkerChoiceStrategyRetries() behavior', async () => {
- const numberOfThreads = 4
- const pool = new FixedThreadPool(
- numberOfThreads,
- './tests/worker-files/thread/testWorker.mjs'
+ expect(getWorkerChoiceStrategiesRetries(threadFixedPool)).toBe(
+ threadFixedPool.info.maxSize * 2
)
- expect(getWorkerChoiceStrategiesRetries(pool)).toBe(pool.info.maxSize * 2)
const workerChoiceStrategyOptions = {
runTime: { median: true },
waitTime: { median: true },
},
}
expect(
- getWorkerChoiceStrategiesRetries(pool, workerChoiceStrategyOptions)
+ getWorkerChoiceStrategiesRetries(
+ threadFixedPool,
+ workerChoiceStrategyOptions
+ )
).toBe(
- pool.info.maxSize +
+ threadFixedPool.info.maxSize +
Object.keys(workerChoiceStrategyOptions.weights).length
)
- await pool.destroy()
})
})
import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs'
describe('Worker node test suite', () => {
- const threadWorkerNode = new WorkerNode(
- WorkerTypes.thread,
- './tests/worker-files/thread/testWorker.mjs',
- {
- tasksQueueBackPressureSize: 12,
- tasksQueueBucketSize: 6,
- tasksQueuePriority: true,
- }
- )
- const clusterWorkerNode = new WorkerNode(
- WorkerTypes.cluster,
- './tests/worker-files/cluster/testWorker.cjs',
- {
- tasksQueueBackPressureSize: 12,
- tasksQueueBucketSize: 6,
- tasksQueuePriority: true,
- }
- )
+ let threadWorkerNode, clusterWorkerNode
+
+ before('Create worker nodes', () => {
+ threadWorkerNode = new WorkerNode(
+ WorkerTypes.thread,
+ './tests/worker-files/thread/testWorker.mjs',
+ {
+ tasksQueueBackPressureSize: 12,
+ tasksQueueBucketSize: 6,
+ tasksQueuePriority: true,
+ }
+ )
+ clusterWorkerNode = new WorkerNode(
+ WorkerTypes.cluster,
+ './tests/worker-files/cluster/testWorker.cjs',
+ {
+ tasksQueueBackPressureSize: 12,
+ tasksQueueBucketSize: 6,
+ tasksQueuePriority: true,
+ }
+ )
+ })
+
+ after('Terminate worker nodes', async () => {
+ await threadWorkerNode.terminate()
+ await clusterWorkerNode.terminate()
+ })
it('Worker node instantiation', () => {
expect(() => new WorkerNode()).toThrow(