X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fabstract%2Fabstract-pool.test.js;h=bf01176de969fe3668ce8ded789673837c4b3fd6;hb=4a581fcdc17b63ec445ce2b8b85a80ffe4961159;hp=81ae3649f1fd70f71e103a818ee51a172870bd7d;hpb=82888165d01dba6a57f5047d4a4c27c6da6025f3;p=poolifier.git diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 81ae3649..bf01176d 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -12,9 +12,6 @@ const { Queue } = require('../../../lib/queue') describe('Abstract pool test suite', () => { const numberOfWorkers = 1 - const workerNotFoundInPoolError = new Error( - 'Worker could not be found in the pool worker nodes' - ) class StubPoolWithRemoveAllWorker extends FixedThreadPool { removeAllWorker () { this.workerNodes = [] @@ -75,7 +72,7 @@ describe('Abstract pool test suite', () => { new FixedThreadPool(0.25, './tests/worker-files/thread/testWorker.js') ).toThrowError( new TypeError( - 'Cannot instantiate a pool with a non integer number of workers' + 'Cannot instantiate a pool with a non safe integer number of workers' ) ) }) @@ -106,7 +103,10 @@ describe('Abstract pool test suite', () => { './tests/worker-files/thread/testWorker.js', { workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED, - workerChoiceStrategyOptions: { medRunTime: true }, + workerChoiceStrategyOptions: { + medRunTime: true, + weights: { 0: 300 } + }, enableEvents: false, enableTasksQueue: true, tasksQueueOptions: { concurrency: 2 }, @@ -124,7 +124,8 @@ describe('Abstract pool test suite', () => { WorkerChoiceStrategies.LESS_USED ) expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({ - medRunTime: true + medRunTime: true, + weights: { 0: 300 } }) expect(pool.opts.messageHandler).toStrictEqual(testHandler) expect(pool.opts.errorHandler).toStrictEqual(testHandler) @@ -155,6 +156,18 @@ describe('Abstract pool test suite', () => { } ) ).toThrowError("Invalid worker choice strategy 'invalidStrategy'") + expect( + () => + new FixedThreadPool( + numberOfWorkers, + './tests/worker-files/thread/testWorker.js', + { + workerChoiceStrategyOptions: { weights: {} } + } + ) + ).toThrowError( + 'Invalid worker choice strategy options: must have a weight for each worker node' + ) }) it('Verify that worker choice strategy options can be set', async () => { @@ -241,7 +254,7 @@ describe('Abstract pool test suite', () => { await pool.destroy() }) - it('Simulate worker not found at getWorkerTasksUsage()', async () => { + it('Simulate worker not found', async () => { const pool = new StubPoolWithRemoveAllWorker( numberOfWorkers, './tests/worker-files/cluster/testWorker.js', @@ -253,9 +266,6 @@ describe('Abstract pool test suite', () => { // Simulate worker not found. pool.removeAllWorker() expect(pool.workerNodes.length).toBe(0) - expect(() => pool.getWorkerTasksUsage()).toThrowError( - workerNotFoundInPoolError - ) await pool.destroy() })