X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fabstract%2Fabstract-pool.test.js;h=038868c2d1502ce721561b23c469bd845e69a8f1;hb=9d16d33ed1bd28d0ff17e278b6a26c9a4f1d1200;hp=eba4a896331ba0760045b5e626fe988a5e0a3ece;hpb=29ee7e9a3f325f87d889ef09ffc1eea4916a782f;p=poolifier.git diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index eba4a896..038868c2 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -1,5 +1,6 @@ const { expect } = require('expect') const { + DynamicClusterPool, DynamicThreadPool, FixedClusterPool, FixedThreadPool, @@ -11,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 = [] @@ -74,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' ) ) }) @@ -240,7 +238,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', @@ -252,9 +250,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() }) @@ -285,7 +280,7 @@ describe('Abstract pool test suite', () => { for (const workerNode of pool.workerNodes) { expect(workerNode.tasksQueue).toBeDefined() expect(workerNode.tasksQueue).toBeInstanceOf(Queue) - expect(workerNode.tasksQueue.size()).toBe(0) + expect(workerNode.tasksQueue.size).toBe(0) } await pool.destroy() }) @@ -398,4 +393,21 @@ describe('Abstract pool test suite', () => { expect(poolBusy).toBe(numberOfWorkers + 1) await pool.destroy() }) + + it('Verify that multiple tasks worker is working', async () => { + const pool = new DynamicClusterPool( + numberOfWorkers, + numberOfWorkers * 2, + './tests/worker-files/cluster/testMultiTasksWorker.js' + ) + const data = { n: 10 } + const result0 = await pool.execute(data) + expect(result0).toBe(false) + const result1 = await pool.execute(data, 'jsonIntegerSerialization') + expect(result1).toBe(false) + const result2 = await pool.execute(data, 'factorial') + expect(result2).toBe(3628800) + const result3 = await pool.execute(data, 'fibonacci') + expect(result3).toBe(89) + }) })