X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fcluster%2Ffixed.test.js;h=9fc2b1b456a4cc5e323a14a276f3633372dba596;hb=0e2c24b4aaed93a6768127f49d898ac427faa147;hp=c28b8021db11f0342ba3130146cc0e54d2b66eb5;hpb=d3d4b67d8301265da89328a0a05ab68438add3ed;p=poolifier.git diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index c28b8021..9fc2b1b4 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -1,5 +1,5 @@ const { expect } = require('expect') -const { FixedClusterPool, PoolEvents } = require('../../../lib/index') +const { FixedClusterPool, PoolEvents } = require('../../../lib') const { WorkerFunctions } = require('../../test-types') const TestUtils = require('../../test-utils') @@ -65,14 +65,14 @@ describe('Fixed cluster 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 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) }) @@ -89,8 +89,8 @@ describe('Fixed cluster pool test suite', () => { }) it('Verify that tasks queuing is working', async () => { - const maxMultiplier = 10 const promises = new Set() + const maxMultiplier = 2 for (let i = 0; i < numberOfWorkers * maxMultiplier; i++) { promises.add(queuePool.execute()) } @@ -100,19 +100,22 @@ describe('Fixed cluster pool test suite', () => { queuePool.opts.tasksQueueOptions.concurrency ) expect(workerNode.tasksUsage.run).toBe(0) - expect(workerNode.tasksQueue.length).toBeGreaterThan(0) + expect(workerNode.tasksQueue.size).toBeGreaterThan(0) } - expect(queuePool.numberOfRunningTasks).toBe(numberOfWorkers) - expect(queuePool.numberOfQueuedTasks).toBe( + expect(queuePool.info.runningTasks).toBe(numberOfWorkers) + expect(queuePool.info.queuedTasks).toBe( + numberOfWorkers * maxMultiplier - numberOfWorkers + ) + expect(queuePool.info.maxQueuedTasks).toBe( numberOfWorkers * maxMultiplier - numberOfWorkers ) 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) + expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(maxMultiplier) + expect(workerNode.tasksQueue.size).toBe(0) } - promises.clear() }) it('Verify that is possible to have a worker that return undefined', async () => { @@ -137,6 +140,11 @@ describe('Fixed cluster pool test suite', () => { expect(inError).toBeDefined() expect(typeof inError === 'string').toBe(true) expect(inError).toBe('Error Message from ClusterWorker') + expect( + errorPool.workerNodes.some( + workerNode => workerNode.tasksUsage.error === 1 + ) + ).toBe(true) }) it('Verify that error handling is working properly:async', async () => { @@ -150,6 +158,11 @@ describe('Fixed cluster pool test suite', () => { expect(inError).toBeDefined() expect(typeof inError === 'string').toBe(true) expect(inError).toBe('Error Message from ClusterWorker:async') + expect( + asyncErrorPool.workerNodes.some( + workerNode => workerNode.tasksUsage.error === 1 + ) + ).toBe(true) }) it('Verify that async function is working properly', async () => { @@ -206,6 +219,6 @@ describe('Fixed cluster pool test suite', () => { expect( () => new FixedClusterPool(0, './tests/worker-files/cluster/testWorker.js') - ).toThrowError(new Error('Cannot instantiate a fixed pool with no worker')) + ).toThrowError('Cannot instantiate a fixed pool with no worker') }) })