X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fthread%2Fdynamic.test.js;h=404f2113d95c3cbefc27ddd9efa8da08b1eeb1cd;hb=dcfcda3a61caf5fd8a14b7794915620bad5b35b6;hp=feb4955d9a9951fbd2dc341028acb76bc638c661;hpb=f06e48d8e14dcfe3277bd16b1bd2463136af13e6;p=poolifier.git diff --git a/tests/pools/thread/dynamic.test.js b/tests/pools/thread/dynamic.test.js index feb4955d..404f2113 100644 --- a/tests/pools/thread/dynamic.test.js +++ b/tests/pools/thread/dynamic.test.js @@ -1,5 +1,5 @@ const { expect } = require('expect') -const { DynamicThreadPool, PoolEvents } = require('../../../lib/index') +const { DynamicThreadPool, PoolEvents } = require('../../../lib') const { WorkerFunctions } = require('../../test-types') const TestUtils = require('../../test-utils') @@ -19,11 +19,11 @@ describe('Dynamic thread pool test suite', () => { let result = await pool.execute({ function: WorkerFunctions.fibonacci }) - expect(result).toBe(false) + expect(result).toBe(121393) result = await pool.execute({ function: WorkerFunctions.factorial }) - expect(result).toBe(false) + expect(result).toBe(9.33262154439441e157) }) it('Verify that new workers are created when required, max size is not exceeded and that after a while new workers will die', async () => { @@ -37,28 +37,28 @@ describe('Dynamic thread pool test suite', () => { // The `busy` event is triggered when the number of submitted tasks at once reach the max number of workers in the dynamic pool. // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the dynamic pool. expect(poolBusy).toBe(max + 1) - const numberOfExitEvents = await TestUtils.waitExits(pool, max - min) + const numberOfExitEvents = await TestUtils.waitWorkerExits(pool, max - min) expect(numberOfExitEvents).toBe(max - min) }) it('Verify scale thread up and down is working', async () => { expect(pool.workerNodes.length).toBe(min) - for (let i = 0; i < max * 10; i++) { + for (let i = 0; i < max * 2; i++) { pool.execute() } expect(pool.workerNodes.length).toBe(max) - await TestUtils.waitExits(pool, max - min) + await TestUtils.waitWorkerExits(pool, max - min) expect(pool.workerNodes.length).toBe(min) - for (let i = 0; i < max * 10; i++) { + for (let i = 0; i < max * 2; i++) { pool.execute() } expect(pool.workerNodes.length).toBe(max) - await TestUtils.waitExits(pool, max - min) + await TestUtils.waitWorkerExits(pool, max - min) expect(pool.workerNodes.length).toBe(min) }) it('Shutdown test', async () => { - const exitPromise = TestUtils.waitExits(pool, min) + const exitPromise = TestUtils.waitWorkerExits(pool, min) await pool.destroy() const numberOfExitEvents = await exitPromise expect(numberOfExitEvents).toBe(min) @@ -66,7 +66,7 @@ describe('Dynamic thread pool test suite', () => { it('Validation of inputs test', () => { expect(() => new DynamicThreadPool(min)).toThrowError( - new Error('Please specify a file with a worker implementation') + 'Please specify a file with a worker implementation' ) }) @@ -94,12 +94,17 @@ describe('Dynamic thread pool test suite', () => { } ) expect(longRunningPool.workerNodes.length).toBe(min) - for (let i = 0; i < max * 10; i++) { + for (let i = 0; i < max * 2; i++) { longRunningPool.execute() } expect(longRunningPool.workerNodes.length).toBe(max) - await TestUtils.waitExits(longRunningPool, max - min) + await TestUtils.waitWorkerExits(longRunningPool, max - min) expect(longRunningPool.workerNodes.length).toBe(min) + expect( + longRunningPool.workerChoiceStrategyContext.workerChoiceStrategies.get( + longRunningPool.workerChoiceStrategyContext.workerChoiceStrategy + ).nextWorkerNodeId + ).toBeLessThan(longRunningPool.workerNodes.length) // We need to clean up the resources after our test await longRunningPool.destroy() }) @@ -116,7 +121,7 @@ describe('Dynamic thread pool test suite', () => { } ) expect(longRunningPool.workerNodes.length).toBe(min) - for (let i = 0; i < max * 10; i++) { + for (let i = 0; i < max * 2; i++) { longRunningPool.execute() } expect(longRunningPool.workerNodes.length).toBe(max)