X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Futils.test.mjs;h=cfa378e16aa37d81b1a4cbb51bfbe7c2a57babc7;hb=bcfb06ce041a682baf396a099c633a848d6a4045;hp=6869bda681315aab9b088bad60677df4e8bcc510;hpb=3ffc32ec66a9c48f39a1b976ebd88cea53824679;p=poolifier.git diff --git a/tests/pools/utils.test.mjs b/tests/pools/utils.test.mjs index 6869bda6..cfa378e1 100644 --- a/tests/pools/utils.test.mjs +++ b/tests/pools/utils.test.mjs @@ -1,25 +1,21 @@ -import { Worker as ThreadWorker } from 'node:worker_threads' import cluster, { Worker as ClusterWorker } from 'node:cluster' +import { Worker as ThreadWorker } from 'node:worker_threads' + import { expect } from 'expect' + import { CircularArray, DEFAULT_CIRCULAR_ARRAY_SIZE } from '../../lib/circular-array.cjs' +import { WorkerTypes } from '../../lib/index.cjs' import { - DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, - buildWorkerChoiceStrategyOptions, createWorker, + DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS, getDefaultTasksQueueOptions, - getWorkerChoiceStrategyRetries, getWorkerId, getWorkerType, updateMeasurementStatistics } from '../../lib/pools/utils.cjs' -import { - FixedClusterPool, - FixedThreadPool, - WorkerTypes -} from '../../lib/index.cjs' describe('Pool utils test suite', () => { it('Verify DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS values', () => { @@ -41,61 +37,6 @@ describe('Pool utils test suite', () => { }) }) - it('Verify getWorkerChoiceStrategyRetries() behavior', async () => { - const numberOfThreads = 4 - const pool = new FixedThreadPool( - numberOfThreads, - './tests/worker-files/thread/testWorker.mjs' - ) - expect(getWorkerChoiceStrategyRetries(pool)).toBe(pool.info.maxSize * 2) - const workerChoiceStrategyOptions = { - runTime: { median: true }, - waitTime: { median: true }, - elu: { median: true }, - weights: { - 0: 100, - 1: 100 - } - } - expect( - getWorkerChoiceStrategyRetries(pool, workerChoiceStrategyOptions) - ).toBe( - pool.info.maxSize + - Object.keys(workerChoiceStrategyOptions.weights).length - ) - await pool.destroy() - }) - - it('Verify buildWorkerChoiceStrategyOptions() behavior', async () => { - const numberOfWorkers = 4 - const pool = new FixedClusterPool( - numberOfWorkers, - './tests/worker-files/cluster/testWorker.cjs' - ) - expect(buildWorkerChoiceStrategyOptions(pool)).toStrictEqual({ - runTime: { median: false }, - waitTime: { median: false }, - elu: { median: false }, - weights: expect.objectContaining({ - 0: expect.any(Number), - [pool.info.maxSize - 1]: expect.any(Number) - }) - }) - const workerChoiceStrategyOptions = { - runTime: { median: true }, - waitTime: { median: true }, - elu: { median: true }, - weights: { - 0: 100, - 1: 100 - } - } - expect( - buildWorkerChoiceStrategyOptions(pool, workerChoiceStrategyOptions) - ).toStrictEqual(workerChoiceStrategyOptions) - await pool.destroy() - }) - it('Verify updateMeasurementStatistics() behavior', () => { const measurementStatistics = { history: new CircularArray()