X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;ds=sidebyside;f=tests%2Fpools%2Fcluster%2Fdynamic.test.mjs;h=870a5f4df9aa0f3bc997b4463f67746d3e7d8c42;hb=a4d25410764bca884efaea4d46ed9bf83b8a8dbb;hp=6e8580e9d7cf07449c26d2fa74476b486b3178fe;hpb=b73887071ac359b50a7f117a76b3edf268841aac;p=poolifier.git diff --git a/tests/pools/cluster/dynamic.test.mjs b/tests/pools/cluster/dynamic.test.mjs index 6e8580e9..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) } @@ -76,7 +76,7 @@ describe('Dynamic cluster pool test suite', () => { it('Validation of inputs test', () => { expect(() => new DynamicClusterPool(min)).toThrow( - "Cannot find the worker file 'undefined'" + 'The worker file path must be specified' ) }) @@ -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() + }) })