X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fthread%2Ffixed.test.js;h=f2b36fa7d9eeb617919c86dcdbbf1d797f7e777e;hb=95ec6006ca39aef0102c82ca42e104a4e9b40b6b;hp=7b4b9bf536acd131c3dcc1a9e729f90e86ff05e4;hpb=594bfb844b5eb66cf533715a6ddad1799b1f5f8f;p=poolifier.git diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index 7b4b9bf5..f2b36fa7 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -72,7 +72,7 @@ describe('Fixed thread pool test suite', () => { expect(result).toBe(false) }) - it('Verify that is possible to invoke the execute method without input', async () => { + it('Verify that is possible to invoke the execute() method without input', async () => { const result = await pool.execute() expect(result).toBe(false) }) @@ -90,9 +90,11 @@ describe('Fixed thread pool test suite', () => { it('Verify that tasks queuing is working', async () => { const maxMultiplier = 10 + const promises = new Set() for (let i = 0; i < numberOfThreads * maxMultiplier; i++) { - queuePool.execute() + promises.add(queuePool.execute()) } + expect(promises.size).toBe(numberOfThreads * maxMultiplier) for (const workerNode of queuePool.workerNodes) { expect(workerNode.tasksUsage.running).toBeLessThanOrEqual( queuePool.opts.tasksQueueOptions.concurrency @@ -100,17 +102,17 @@ describe('Fixed thread pool test suite', () => { expect(workerNode.tasksUsage.run).toBe(0) expect(workerNode.tasksQueue.length).toBeGreaterThan(0) } - // FIXME: wait for ongoing tasks to be executed - const promises = [] - for (let i = 0; i < numberOfThreads * maxMultiplier; i++) { - promises.push(queuePool.execute()) - } + expect(queuePool.numberOfRunningTasks).toBe(numberOfThreads) + expect(queuePool.numberOfQueuedTasks).toBe( + numberOfThreads * maxMultiplier - numberOfThreads + ) await Promise.all(promises) for (const workerNode of queuePool.workerNodes) { expect(workerNode.tasksUsage.running).toBe(0) expect(workerNode.tasksUsage.run).toBeGreaterThan(0) expect(workerNode.tasksQueue.length).toBe(0) } + promises.clear() }) it('Verify that is possible to have a worker that return undefined', async () => { @@ -184,6 +186,6 @@ describe('Fixed thread pool test suite', () => { it('Verify that a pool with zero worker fails', async () => { expect( () => new FixedThreadPool(0, './tests/worker-files/thread/testWorker.js') - ).toThrowError(new Error('Cannot instantiate a fixed pool with no worker')) + ).toThrowError('Cannot instantiate a fixed pool with no worker') }) })