X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fcluster%2Fdynamic.test.mjs;h=870a5f4df9aa0f3bc997b4463f67746d3e7d8c42;hb=3bcbd4c5be5678988281342a1fc1f6a62f9c77d7;hp=2a654b6a878cab03a4da44afb7200ca122acf0c1;hpb=c3719753af0a9be03abf722a7543495359e817b5;p=poolifier.git diff --git a/tests/pools/cluster/dynamic.test.mjs b/tests/pools/cluster/dynamic.test.mjs index 2a654b6a..870a5f4d 100644 --- a/tests/pools/cluster/dynamic.test.mjs +++ b/tests/pools/cluster/dynamic.test.mjs @@ -1,7 +1,7 @@ import { expect } from 'expect' -import { DynamicClusterPool, PoolEvents } from '../../../lib/index.js' -import { TaskFunctions } from '../../test-types.js' -import { sleep, waitWorkerEvents } from '../../test-utils.js' +import { DynamicClusterPool, PoolEvents } from '../../../lib/index.cjs' +import { TaskFunctions } from '../../test-types.cjs' +import { sleep, waitWorkerEvents } from '../../test-utils.cjs' describe('Dynamic cluster pool test suite', () => { const min = 1 @@ -9,7 +9,7 @@ describe('Dynamic cluster pool test suite', () => { const pool = new DynamicClusterPool( min, max, - './tests/worker-files/cluster/testWorker.js', + './tests/worker-files/cluster/testWorker.cjs', { errorHandler: e => console.error(e) } @@ -84,7 +84,7 @@ describe('Dynamic cluster pool test suite', () => { const pool = new DynamicClusterPool( min, max, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) const result = await pool.execute() expect(result).toStrictEqual({ ok: 1 }) @@ -96,7 +96,7 @@ describe('Dynamic cluster pool test suite', () => { const longRunningPool = new DynamicClusterPool( min, max, - './tests/worker-files/cluster/longRunningWorkerHardBehavior.js', + './tests/worker-files/cluster/longRunningWorkerHardBehavior.cjs', { errorHandler: e => console.error(e), onlineHandler: () => console.info('long executing worker is online'), @@ -123,7 +123,7 @@ describe('Dynamic cluster pool test suite', () => { const longRunningPool = new DynamicClusterPool( min, max, - './tests/worker-files/cluster/longRunningWorkerSoftBehavior.js', + './tests/worker-files/cluster/longRunningWorkerSoftBehavior.cjs', { errorHandler: e => console.error(e), onlineHandler: () => console.info('long executing worker is online'), @@ -146,10 +146,29 @@ describe('Dynamic cluster pool test suite', () => { const pool = new DynamicClusterPool( 0, max, - './tests/worker-files/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.cjs' ) expect(pool).toBeInstanceOf(DynamicClusterPool) // We need to clean up the resources after our test await pool.destroy() }) + + it.skip('Verify that a pool with zero worker works', async () => { + const pool = new DynamicClusterPool( + 0, + max, + './tests/worker-files/thread/testWorker.mjs' + ) + expect(pool.starting).toBe(false) + expect(pool.workerNodes.length).toBe(pool.info.minSize) + const maxMultiplier = 10000 + const promises = new Set() + for (let i = 0; i < max * maxMultiplier; i++) { + promises.add(pool.execute()) + } + await Promise.all(promises) + expect(pool.workerNodes.length).toBe(max) + // We need to clean up the resources after our test + await pool.destroy() + }) })