X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fabstract%2Fabstract-pool.test.js;h=108fb32a03f1c10d629a9a4bf33da46e4169987d;hb=a32959dad7ec3668f607e26153ad7610ff5438f9;hp=db45fa077620d225d4a8367ebd3d37c9d7cc9da7;hpb=86bf340d3da6dd24b2963b86e093b23104a2c265;p=poolifier.git diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index db45fa07..108fb32a 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -11,7 +11,7 @@ const { CircularArray } = require('../../../lib/circular-array') const { Queue } = require('../../../lib/queue') describe('Abstract pool test suite', () => { - const numberOfWorkers = 1 + const numberOfWorkers = 2 class StubPoolWithRemoveAllWorker extends FixedThreadPool { removeAllWorker () { this.workerNodes = [] @@ -106,7 +106,7 @@ describe('Abstract pool test suite', () => { workerChoiceStrategy: WorkerChoiceStrategies.LEAST_USED, workerChoiceStrategyOptions: { medRunTime: true, - weights: { 0: 300 } + weights: { 0: 300, 1: 200 } }, enableEvents: false, enableTasksQueue: true, @@ -126,7 +126,7 @@ describe('Abstract pool test suite', () => { ) expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({ medRunTime: true, - weights: { 0: 300 } + weights: { 0: 300, 1: 200 } }) expect(pool.opts.messageHandler).toStrictEqual(testHandler) expect(pool.opts.errorHandler).toStrictEqual(testHandler) @@ -328,13 +328,14 @@ describe('Abstract pool test suite', () => { './tests/worker-files/cluster/testWorker.js' ) const promises = [] - for (let i = 0; i < numberOfWorkers * 2; i++) { + const maxMultiplier = 2 + for (let i = 0; i < numberOfWorkers * maxMultiplier; i++) { promises.push(pool.execute()) } for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ run: 0, - running: numberOfWorkers * 2, + running: maxMultiplier, runTime: 0, runTimeHistory: expect.any(CircularArray), avgRunTime: 0, @@ -349,7 +350,7 @@ describe('Abstract pool test suite', () => { await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: numberOfWorkers * 2, + run: maxMultiplier, running: 0, runTime: 0, runTimeHistory: expect.any(CircularArray), @@ -372,15 +373,16 @@ describe('Abstract pool test suite', () => { './tests/worker-files/thread/testWorker.js' ) const promises = [] - for (let i = 0; i < numberOfWorkers * 2; i++) { + const maxMultiplier = 2 + for (let i = 0; i < numberOfWorkers * maxMultiplier; i++) { promises.push(pool.execute()) } await Promise.all(promises) for (const workerNode of pool.workerNodes) { expect(workerNode.tasksUsage).toStrictEqual({ - run: numberOfWorkers * 2, + run: expect.any(Number), running: 0, - runTime: expect.any(Number), + runTime: 0, runTimeHistory: expect.any(CircularArray), avgRunTime: 0, medRunTime: 0, @@ -390,12 +392,11 @@ describe('Abstract pool test suite', () => { medWaitTime: 0, error: 0 }) - expect(workerNode.tasksUsage.runTime).toBeGreaterThanOrEqual(0) - expect(workerNode.tasksUsage.avgRunTime).toBeGreaterThanOrEqual(0) + expect(workerNode.tasksUsage.run).toBeGreaterThan(0) + expect(workerNode.tasksUsage.run).toBeLessThanOrEqual(maxMultiplier) } pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE) for (const workerNode of pool.workerNodes) { - expect(workerNode.tasksUsage).toBeDefined() expect(workerNode.tasksUsage).toStrictEqual({ run: 0, running: 0, @@ -410,6 +411,7 @@ describe('Abstract pool test suite', () => { error: 0 }) expect(workerNode.tasksUsage.runTimeHistory.length).toBe(0) + expect(workerNode.tasksUsage.waitTimeHistory.length).toBe(0) } await pool.destroy() }) @@ -428,8 +430,8 @@ describe('Abstract pool test suite', () => { } await Promise.all(promises) // The `full` event is triggered when the number of submitted tasks at once reach the max number of workers in the dynamic pool. - // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the dynamic pool. - expect(poolFull).toBe(numberOfWorkers + 1) + // 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) await pool.destroy() })