X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fthread%2Ffixed.test.js;h=7b4b9bf536acd131c3dcc1a9e729f90e86ff05e4;hb=594bfb844b5eb66cf533715a6ddad1799b1f5f8f;hp=cf5c3175df42d9a5c94732e46d440af5a8f5deb1;hpb=d710242dd39f5dd418b0a89536a9ad88c147fe3b;p=poolifier.git diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index cf5c3175..7b4b9bf5 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -12,6 +12,17 @@ describe('Fixed thread pool test suite', () => { errorHandler: e => console.error(e) } ) + const queuePool = new FixedThreadPool( + numberOfThreads, + './tests/worker-files/thread/testWorker.js', + { + enableTasksQueue: true, + tasksQueueOptions: { + concurrency: 2 + }, + errorHandler: e => console.error(e) + } + ) const emptyPool = new FixedThreadPool( numberOfThreads, './tests/worker-files/thread/emptyWorker.js', @@ -47,6 +58,7 @@ describe('Fixed thread pool test suite', () => { await errorPool.destroy() await asyncErrorPool.destroy() await emptyPool.destroy() + await queuePool.destroy() }) it('Verify that the function is executed in a worker thread', async () => { @@ -76,6 +88,31 @@ describe('Fixed thread pool test suite', () => { expect(poolBusy).toBe(numberOfThreads + 1) }) + it('Verify that tasks queuing is working', async () => { + const maxMultiplier = 10 + for (let i = 0; i < numberOfThreads * maxMultiplier; i++) { + queuePool.execute() + } + for (const workerNode of queuePool.workerNodes) { + expect(workerNode.tasksUsage.running).toBeLessThanOrEqual( + queuePool.opts.tasksQueueOptions.concurrency + ) + 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()) + } + 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) + } + }) + it('Verify that is possible to have a worker that return undefined', async () => { const result = await emptyPool.execute() expect(result).toBeUndefined()