X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fabstract%2Fabstract-pool.test.js;h=96dc9a10ad4120a97455cd11d43e9bae38790c3c;hb=ea7a90d36354a4e1c833271571c6f3eb80428600;hp=24c7debd3c86deda03f4e312682d60546ed07c61;hpb=bf9549aef8a23a3931e19040dadb7f1e8e6422b5;p=poolifier.git diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 24c7debd..96dc9a10 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -5,25 +5,22 @@ const { WorkerChoiceStrategies } = require('../../../lib/index') -const numberOfWorkers = 1 - -const workerNotFoundInTasksUsageMapError = new Error( - 'Worker could not be found in worker tasks usage map' -) - -class StubPoolWithWorkerTasksUsageMapClear extends FixedThreadPool { - removeAllWorker () { - this.workersTasksUsage.clear() +describe('Abstract pool test suite', () => { + const numberOfWorkers = 1 + const workerNotFoundInTasksUsageMapError = new Error( + 'Worker could not be found in worker tasks usage map' + ) + class StubPoolWithWorkerTasksUsageMapClear extends FixedThreadPool { + removeAllWorker () { + this.workersTasksUsage.clear() + } } -} - -class StubPoolWithIsMainMethod extends FixedThreadPool { - isMain () { - return false + class StubPoolWithIsMainMethod extends FixedThreadPool { + isMain () { + return false + } } -} -describe('Abstract pool test suite', () => { it('Simulate pool creation from a non main thread/process', () => { expect( () => @@ -162,11 +159,26 @@ describe('Abstract pool test suite', () => { pool.destroy() }) - it('Simulate worker not found during updateWorkerTasksRunTime', () => { + it('Simulate worker not found during updateWorkerTasksRunTime with strategy not requiring it', () => { + const pool = new StubPoolWithWorkerTasksUsageMapClear( + numberOfWorkers, + './tests/worker-files/cluster/testWorker.js', + { + errorHandler: e => console.error(e) + } + ) + // Simulate worker not found. + pool.removeAllWorker() + expect(() => pool.updateWorkerTasksRunTime()).not.toThrowError() + pool.destroy() + }) + + it('Simulate worker not found during updateWorkerTasksRunTime with strategy requiring it', () => { const pool = new StubPoolWithWorkerTasksUsageMapClear( numberOfWorkers, './tests/worker-files/cluster/testWorker.js', { + workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE, errorHandler: e => console.error(e) } ) @@ -200,7 +212,7 @@ describe('Abstract pool test suite', () => { ) const promises = [] for (let i = 0; i < numberOfWorkers * 2; i++) { - promises.push(pool.execute({ test: 'test' })) + promises.push(pool.execute()) } for (const tasksUsage of pool.workersTasksUsage.values()) { expect(tasksUsage).toBeDefined() @@ -229,7 +241,7 @@ describe('Abstract pool test suite', () => { let poolBusy = 0 pool.emitter.on('busy', () => poolBusy++) for (let i = 0; i < numberOfWorkers * 2; i++) { - promises.push(pool.execute({ test: 'test' })) + promises.push(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.