X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fabstract%2Fabstract-pool.test.js;h=d4b147f78f4cd13e62aedbf5a8cac0af8d56884a;hb=f751010550f07200428ca708afb2ec1d242cf7a7;hp=fc386f375513cbfe35e9eb220ee5598e1e562008;hpb=f0d7f80366c1012a9c63ad155c51924ffb40c4fd;p=poolifier.git diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index fc386f37..d4b147f7 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -11,6 +11,7 @@ const { } = require('../../../lib') const { CircularArray } = require('../../../lib/circular-array') const { Queue } = require('../../../lib/queue') +const { version } = require('../../../package.json') describe('Abstract pool test suite', () => { const numberOfWorkers = 2 @@ -329,6 +330,21 @@ describe('Abstract pool test suite', () => { median: false } }) + expect(() => + pool.setWorkerChoiceStrategyOptions('invalidWorkerChoiceStrategyOptions') + ).toThrowError( + 'Invalid worker choice strategy options: must be a plain object' + ) + expect(() => + pool.setWorkerChoiceStrategyOptions({ weights: {} }) + ).toThrowError( + 'Invalid worker choice strategy options: must have a weight for each worker node' + ) + expect(() => + pool.setWorkerChoiceStrategyOptions({ measurement: 'invalidMeasurement' }) + ).toThrowError( + "Invalid worker choice strategy options: invalid measurement 'invalidMeasurement'" + ) await pool.destroy() }) @@ -378,6 +394,7 @@ describe('Abstract pool test suite', () => { './tests/worker-files/thread/testWorker.js' ) expect(pool.info).toStrictEqual({ + version, type: PoolTypes.fixed, worker: WorkerTypes.thread, minSize: numberOfWorkers, @@ -395,9 +412,10 @@ describe('Abstract pool test suite', () => { pool = new DynamicClusterPool( numberOfWorkers, numberOfWorkers * 2, - './tests/worker-files/thread/testWorker.js' + './tests/worker-files/cluster/testWorker.js' ) expect(pool.info).toStrictEqual({ + version, type: PoolTypes.dynamic, worker: WorkerTypes.cluster, minSize: numberOfWorkers, @@ -417,7 +435,7 @@ describe('Abstract pool test suite', () => { it('Simulate worker not found', async () => { const pool = new StubPoolWithRemoveAllWorker( numberOfWorkers, - './tests/worker-files/cluster/testWorker.js', + './tests/worker-files/thread/testWorker.js', { errorHandler: e => console.error(e) } @@ -435,21 +453,26 @@ describe('Abstract pool test suite', () => { './tests/worker-files/cluster/testWorker.js' ) for (const workerNode of pool.workerNodes) { - expect(workerNode.workerUsage).toStrictEqual({ + expect(workerNode.usage).toStrictEqual({ tasks: { executed: 0, executing: 0, queued: 0, + maxQueued: 0, failed: 0 }, runTime: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) }, waitTime: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) @@ -457,17 +480,20 @@ describe('Abstract pool test suite', () => { elu: { idle: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) }, active: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) - }, - utilization: 0 + } } }) } @@ -483,6 +509,7 @@ describe('Abstract pool test suite', () => { expect(workerNode.tasksQueue).toBeDefined() expect(workerNode.tasksQueue).toBeInstanceOf(Queue) expect(workerNode.tasksQueue.size).toBe(0) + expect(workerNode.tasksQueue.maxSize).toBe(0) } await pool.destroy() }) @@ -498,21 +525,26 @@ describe('Abstract pool test suite', () => { promises.add(pool.execute()) } for (const workerNode of pool.workerNodes) { - expect(workerNode.workerUsage).toStrictEqual({ + expect(workerNode.usage).toStrictEqual({ tasks: { executed: 0, executing: maxMultiplier, queued: 0, + maxQueued: 0, failed: 0 }, runTime: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) }, waitTime: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) @@ -520,37 +552,45 @@ describe('Abstract pool test suite', () => { elu: { idle: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) }, active: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) - }, - utilization: 0 + } } }) } await Promise.all(promises) for (const workerNode of pool.workerNodes) { - expect(workerNode.workerUsage).toStrictEqual({ + expect(workerNode.usage).toStrictEqual({ tasks: { executed: maxMultiplier, executing: 0, queued: 0, + maxQueued: 0, failed: 0 }, runTime: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) }, waitTime: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) @@ -558,17 +598,20 @@ describe('Abstract pool test suite', () => { elu: { idle: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) }, active: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) - }, - utilization: 0 + } } }) } @@ -588,21 +631,26 @@ describe('Abstract pool test suite', () => { } await Promise.all(promises) for (const workerNode of pool.workerNodes) { - expect(workerNode.workerUsage).toStrictEqual({ + expect(workerNode.usage).toStrictEqual({ tasks: { executed: expect.any(Number), executing: 0, queued: 0, + maxQueued: 0, failed: 0 }, runTime: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) }, waitTime: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) @@ -610,41 +658,47 @@ describe('Abstract pool test suite', () => { elu: { idle: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) }, active: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) - }, - utilization: 0 + } } }) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThan(0) - expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( - maxMultiplier - ) + expect(workerNode.usage.tasks.executed).toBeGreaterThan(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(maxMultiplier) } pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE) for (const workerNode of pool.workerNodes) { - expect(workerNode.workerUsage).toStrictEqual({ + expect(workerNode.usage).toStrictEqual({ tasks: { executed: 0, executing: 0, queued: 0, + maxQueued: 0, failed: 0 }, runTime: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) }, waitTime: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) @@ -652,21 +706,24 @@ describe('Abstract pool test suite', () => { elu: { idle: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) }, active: { aggregate: 0, + maximum: 0, + minimum: 0, average: 0, median: 0, history: expect.any(CircularArray) - }, - utilization: 0 + } } }) - expect(workerNode.workerUsage.runTime.history.length).toBe(0) - expect(workerNode.workerUsage.waitTime.history.length).toBe(0) + expect(workerNode.usage.runTime.history.length).toBe(0) + expect(workerNode.usage.waitTime.history.length).toBe(0) } await pool.destroy() }) @@ -692,6 +749,7 @@ describe('Abstract pool test suite', () => { // So in total numberOfWorkers * 2 times for a loop submitting up to numberOfWorkers * 2 tasks to the dynamic pool with min = max = numberOfWorkers. expect(poolFull).toBe(numberOfWorkers * 2) expect(poolInfo).toStrictEqual({ + version, type: PoolTypes.dynamic, worker: WorkerTypes.thread, minSize: expect.any(Number), @@ -728,6 +786,7 @@ describe('Abstract pool test suite', () => { // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the fixed pool. expect(poolBusy).toBe(numberOfWorkers + 1) expect(poolInfo).toStrictEqual({ + version, type: PoolTypes.fixed, worker: WorkerTypes.thread, minSize: expect.any(Number), @@ -758,6 +817,6 @@ describe('Abstract pool test suite', () => { const result2 = await pool.execute(data, 'factorial') expect(result2).toBe(3628800) const result3 = await pool.execute(data, 'fibonacci') - expect(result3).toBe(89) + expect(result3).toBe(55) }) })