X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Futils.test.mjs;h=610b92c3ce62cba912ab9273b14d5cb2077f9884;hb=cabd0dd78cf4cfe588974e09c7e8e7beffd70dcf;hp=bf0c72afadadc78819bd5d938a30f962496f1fee;hpb=229e9e73566ed1960ba5be0534fb3aa2eeb115eb;p=poolifier.git diff --git a/tests/pools/utils.test.mjs b/tests/pools/utils.test.mjs index bf0c72af..610b92c3 100644 --- a/tests/pools/utils.test.mjs +++ b/tests/pools/utils.test.mjs @@ -1,11 +1,29 @@ +import { Worker as ThreadWorker } from 'node:worker_threads' +import { Worker as ClusterWorker } from 'node:cluster' import { expect } from 'expect' import { CircularArray, DEFAULT_CIRCULAR_ARRAY_SIZE -} from '../../lib/circular-array.js' -import { updateMeasurementStatistics } from '../../lib/pools/utils.js' +} from '../../lib/circular-array.cjs' +import { + createWorker, + getDefaultTasksQueueOptions, + updateMeasurementStatistics +} from '../../lib/pools/utils.cjs' +import { WorkerTypes } from '../../lib/index.cjs' describe('Pool utils test suite', () => { + it('Verify getDefaultTasksQueueOptions() behavior', () => { + const poolMaxSize = 4 + expect(getDefaultTasksQueueOptions(poolMaxSize)).toStrictEqual({ + concurrency: 1, + size: Math.pow(poolMaxSize, 2), + taskStealing: true, + tasksStealingOnBackPressure: true, + tasksFinishedTimeout: 2000 + }) + }) + it('Verify updateMeasurementStatistics() behavior', () => { const measurementStatistics = { history: new CircularArray() @@ -92,4 +110,21 @@ describe('Pool utils test suite', () => { ) }) }) + + it('Verify createWorker() behavior', () => { + expect( + createWorker( + WorkerTypes.thread, + './tests/worker-files/thread/testWorker.mjs', + {} + ) + ).toBeInstanceOf(ThreadWorker) + expect( + createWorker( + WorkerTypes.cluster, + './tests/worker-files/cluster/testWorker.mjs', + {} + ) + ).toBeInstanceOf(ClusterWorker) + }) })