X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fabstract%2Fabstract-pool.test.js;h=02baefaf93b5639867d8bb6e852dce39c25dfa57;hb=1d6aaa0a809637ba26d80288126f5a160eb8ce60;hp=a852bab430185b467176fae595fb1f8ddd7fe78f;hpb=0d80593b9a7596645612087f687fc6f5cab3101a;p=poolifier.git diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index a852bab4..02baefaf 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 = [] @@ -105,8 +102,11 @@ describe('Abstract pool test suite', () => { numberOfWorkers, './tests/worker-files/thread/testWorker.js', { - workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED, - workerChoiceStrategyOptions: { medRunTime: true }, + workerChoiceStrategy: WorkerChoiceStrategies.LEAST_USED, + workerChoiceStrategyOptions: { + medRunTime: true, + weights: { 0: 300 } + }, enableEvents: false, enableTasksQueue: true, tasksQueueOptions: { concurrency: 2 }, @@ -121,10 +121,11 @@ describe('Abstract pool test suite', () => { expect(pool.opts.enableTasksQueue).toBe(true) expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 2 }) expect(pool.opts.workerChoiceStrategy).toBe( - WorkerChoiceStrategies.LESS_USED + WorkerChoiceStrategies.LEAST_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() })