X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fabstract%2Fabstract-pool.test.js;h=ec552e986003d859f38fe0557d6d8727c23d7ceb;hb=a1763c54c962c69b5e02a30c0909724986495fcd;hp=0929adc36a60dcfa0422ad6908041484736ee28c;hpb=ce9e97f17ed0d1b2928919244dce5a7887f843f5;p=poolifier.git diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 0929adc3..ec552e98 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -765,31 +765,25 @@ describe('Abstract pool test suite', () => { await pool.destroy() }) - it("Verify that pool event emitter 'full' event can register a callback", async () => { - const pool = new DynamicThreadPool( + it("Verify that pool event emitter 'ready' event can register a callback", async () => { + const pool = new DynamicClusterPool( Math.floor(numberOfWorkers / 2), numberOfWorkers, - './tests/worker-files/thread/testWorker.js' + './tests/worker-files/cluster/testWorker.js' ) - const promises = new Set() - let poolFull = 0 let poolInfo - pool.emitter.on(PoolEvents.full, (info) => { - ++poolFull + let poolReady = 0 + pool.emitter.on(PoolEvents.ready, (info) => { + ++poolReady poolInfo = info }) - for (let i = 0; i < numberOfWorkers * 2; i++) { - promises.add(pool.execute()) - } - await Promise.all(promises) - // The `full` event is triggered when the number of submitted tasks at once reach the maximum number of workers in the dynamic pool. - // So in total numberOfWorkers * 2 - 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the dynamic pool with min = (max = numberOfWorkers) / 2. - expect(poolFull).toBe(numberOfWorkers * 2 - 1) + await waitPoolEvents(pool, PoolEvents.ready, 1) + expect(poolReady).toBe(1) expect(poolInfo).toStrictEqual({ version, type: PoolTypes.dynamic, - worker: WorkerTypes.thread, - ready: expect.any(Boolean), + worker: WorkerTypes.cluster, + ready: true, strategy: WorkerChoiceStrategies.ROUND_ROBIN, minSize: expect.any(Number), maxSize: expect.any(Number), @@ -803,25 +797,30 @@ describe('Abstract pool test suite', () => { await pool.destroy() }) - it("Verify that pool event emitter 'ready' event can register a callback", async () => { - const pool = new DynamicClusterPool( - Math.floor(numberOfWorkers / 2), + it("Verify that pool event emitter 'busy' event can register a callback", async () => { + const pool = new FixedThreadPool( numberOfWorkers, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/thread/testWorker.js' ) + const promises = new Set() + let poolBusy = 0 let poolInfo - let poolReady = 0 - pool.emitter.on(PoolEvents.ready, (info) => { - ++poolReady + pool.emitter.on(PoolEvents.busy, (info) => { + ++poolBusy poolInfo = info }) - await waitPoolEvents(pool, PoolEvents.ready, 1) - expect(poolReady).toBe(1) + for (let i = 0; i < numberOfWorkers * 2; i++) { + promises.add(pool.execute()) + } + await Promise.all(promises) + // The `busy` event is triggered when the number of submitted tasks at once reach the number of fixed pool workers. + // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the fixed pool. + expect(poolBusy).toBe(numberOfWorkers + 1) expect(poolInfo).toStrictEqual({ version, - type: PoolTypes.dynamic, - worker: WorkerTypes.cluster, - ready: true, + type: PoolTypes.fixed, + worker: WorkerTypes.thread, + ready: expect.any(Boolean), strategy: WorkerChoiceStrategies.ROUND_ROBIN, minSize: expect.any(Number), maxSize: expect.any(Number), @@ -835,28 +834,29 @@ describe('Abstract pool test suite', () => { await pool.destroy() }) - it("Verify that pool event emitter 'busy' event can register a callback", async () => { - const pool = new FixedThreadPool( + it("Verify that pool event emitter 'full' event can register a callback", async () => { + const pool = new DynamicThreadPool( + Math.floor(numberOfWorkers / 2), numberOfWorkers, './tests/worker-files/thread/testWorker.js' ) const promises = new Set() - let poolBusy = 0 + let poolFull = 0 let poolInfo - pool.emitter.on(PoolEvents.busy, (info) => { - ++poolBusy + pool.emitter.on(PoolEvents.full, (info) => { + ++poolFull poolInfo = info }) for (let i = 0; i < numberOfWorkers * 2; i++) { promises.add(pool.execute()) } await Promise.all(promises) - // The `busy` event is triggered when the number of submitted tasks at once reach the number of fixed pool workers. - // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the fixed pool. - expect(poolBusy).toBe(numberOfWorkers + 1) + // The `full` event is triggered when the number of submitted tasks at once reach the maximum number of workers in the dynamic pool. + // So in total numberOfWorkers * 2 - 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the dynamic pool with min = (max = numberOfWorkers) / 2. + expect(poolFull).toBe(numberOfWorkers * 2 - 1) expect(poolInfo).toStrictEqual({ version, - type: PoolTypes.fixed, + type: PoolTypes.dynamic, worker: WorkerTypes.thread, ready: expect.any(Boolean), strategy: WorkerChoiceStrategies.ROUND_ROBIN,