X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fabstract-pool.test.mjs;h=4b32e253a3aed5c203bfff7476d49a02a6b4488c;hb=423e70bd0583811e33d41d94e2fda10a03641b47;hp=a10222610c4ee064164fba8b03d55879db0472a9;hpb=d35e571704515a8b729d3455e4784054f07c368f;p=poolifier.git diff --git a/tests/pools/abstract-pool.test.mjs b/tests/pools/abstract-pool.test.mjs index a1022261..4b32e253 100644 --- a/tests/pools/abstract-pool.test.mjs +++ b/tests/pools/abstract-pool.test.mjs @@ -221,6 +221,7 @@ describe('Abstract pool test suite', () => { './tests/worker-files/thread/testWorker.mjs' ) expect(pool.emitter).toBeInstanceOf(EventEmitterAsyncResource) + expect(pool.emitter.eventNames()).toStrictEqual([]) expect(pool.opts).toStrictEqual({ startWorkers: true, enableEvents: true, @@ -228,24 +229,9 @@ describe('Abstract pool test suite', () => { enableTasksQueue: false, workerChoiceStrategy: WorkerChoiceStrategies.ROUND_ROBIN }) - expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({ - retries: - pool.info.maxSize + - Object.keys(pool.workerChoiceStrategyContext.opts.weights).length, - runTime: { median: false }, - waitTime: { median: false }, - elu: { median: false }, - weights: expect.objectContaining({ - 0: expect.any(Number), - [pool.info.maxSize - 1]: expect.any(Number) - }) - }) for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext .workerChoiceStrategies) { expect(workerChoiceStrategy.opts).toStrictEqual({ - retries: - pool.info.maxSize + - Object.keys(workerChoiceStrategy.opts.weights).length, runTime: { median: false }, waitTime: { median: false }, elu: { median: false }, @@ -299,21 +285,9 @@ describe('Abstract pool test suite', () => { errorHandler: testHandler, exitHandler: testHandler }) - expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({ - retries: - pool.info.maxSize + - Object.keys(pool.opts.workerChoiceStrategyOptions.weights).length, - runTime: { median: true }, - waitTime: { median: false }, - elu: { median: false }, - weights: { 0: 300, 1: 200 } - }) for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext .workerChoiceStrategies) { expect(workerChoiceStrategy.opts).toStrictEqual({ - retries: - pool.info.maxSize + - Object.keys(pool.opts.workerChoiceStrategyOptions.weights).length, runTime: { median: true }, waitTime: { median: false }, elu: { median: false }, @@ -470,24 +444,9 @@ describe('Abstract pool test suite', () => { { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE } ) expect(pool.opts.workerChoiceStrategyOptions).toBeUndefined() - expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({ - retries: - pool.info.maxSize + - Object.keys(pool.workerChoiceStrategyContext.opts.weights).length, - runTime: { median: false }, - waitTime: { median: false }, - elu: { median: false }, - weights: expect.objectContaining({ - 0: expect.any(Number), - [pool.info.maxSize - 1]: expect.any(Number) - }) - }) for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext .workerChoiceStrategies) { expect(workerChoiceStrategy.opts).toStrictEqual({ - retries: - pool.info.maxSize + - Object.keys(workerChoiceStrategy.opts.weights).length, runTime: { median: false }, waitTime: { median: false }, elu: { median: false }, @@ -524,24 +483,9 @@ describe('Abstract pool test suite', () => { runTime: { median: true }, elu: { median: true } }) - expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({ - retries: - pool.info.maxSize + - Object.keys(pool.workerChoiceStrategyContext.opts.weights).length, - runTime: { median: true }, - waitTime: { median: false }, - elu: { median: true }, - weights: expect.objectContaining({ - 0: expect.any(Number), - [pool.info.maxSize - 1]: expect.any(Number) - }) - }) for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext .workerChoiceStrategies) { expect(workerChoiceStrategy.opts).toStrictEqual({ - retries: - pool.info.maxSize + - Object.keys(workerChoiceStrategy.opts.weights).length, runTime: { median: true }, waitTime: { median: false }, elu: { median: true }, @@ -578,24 +522,9 @@ describe('Abstract pool test suite', () => { runTime: { median: false }, elu: { median: false } }) - expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({ - retries: - pool.info.maxSize + - Object.keys(pool.workerChoiceStrategyContext.opts.weights).length, - runTime: { median: false }, - waitTime: { median: false }, - elu: { median: false }, - weights: expect.objectContaining({ - 0: expect.any(Number), - [pool.info.maxSize - 1]: expect.any(Number) - }) - }) for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext .workerChoiceStrategies) { expect(workerChoiceStrategy.opts).toStrictEqual({ - retries: - pool.info.maxSize + - Object.keys(workerChoiceStrategy.opts.weights).length, runTime: { median: false }, waitTime: { median: false }, elu: { median: false }, @@ -775,6 +704,7 @@ describe('Abstract pool test suite', () => { started: true, ready: true, strategy: WorkerChoiceStrategies.ROUND_ROBIN, + strategyRetries: 0, minSize: numberOfWorkers, maxSize: numberOfWorkers, workerNodes: numberOfWorkers, @@ -797,6 +727,7 @@ describe('Abstract pool test suite', () => { started: true, ready: true, strategy: WorkerChoiceStrategies.ROUND_ROBIN, + strategyRetries: 0, minSize: Math.floor(numberOfWorkers / 2), maxSize: numberOfWorkers, workerNodes: Math.floor(numberOfWorkers / 2), @@ -933,8 +864,8 @@ describe('Abstract pool test suite', () => { ) expect(pool.info.started).toBe(false) expect(pool.info.ready).toBe(false) - expect(pool.readyEventEmitted).toBe(false) expect(pool.workerNodes).toStrictEqual([]) + expect(pool.readyEventEmitted).toBe(false) await expect(pool.execute()).rejects.toThrow( new Error('Cannot execute a task on not started pool') ) @@ -1146,6 +1077,7 @@ describe('Abstract pool test suite', () => { started: true, ready: true, strategy: WorkerChoiceStrategies.ROUND_ROBIN, + strategyRetries: expect.any(Number), minSize: expect.any(Number), maxSize: expect.any(Number), workerNodes: expect.any(Number), @@ -1186,6 +1118,7 @@ describe('Abstract pool test suite', () => { started: true, ready: true, strategy: WorkerChoiceStrategies.ROUND_ROBIN, + strategyRetries: expect.any(Number), minSize: expect.any(Number), maxSize: expect.any(Number), workerNodes: expect.any(Number), @@ -1225,6 +1158,7 @@ describe('Abstract pool test suite', () => { started: true, ready: true, strategy: WorkerChoiceStrategies.ROUND_ROBIN, + strategyRetries: expect.any(Number), minSize: expect.any(Number), maxSize: expect.any(Number), workerNodes: expect.any(Number), @@ -1267,6 +1201,7 @@ describe('Abstract pool test suite', () => { started: true, ready: true, strategy: WorkerChoiceStrategies.ROUND_ROBIN, + strategyRetries: expect.any(Number), minSize: expect.any(Number), maxSize: expect.any(Number), workerNodes: expect.any(Number), @@ -1311,7 +1246,7 @@ describe('Abstract pool test suite', () => { const elapsedTime = performance.now() - startTime expect(tasksFinished).toBeLessThanOrEqual(numberOfWorkers * maxMultiplier) expect(elapsedTime).toBeGreaterThanOrEqual(2000) - expect(elapsedTime).toBeLessThanOrEqual(tasksFinishedTimeout + 400) + expect(elapsedTime).toBeLessThanOrEqual(tasksFinishedTimeout + 800) }) it('Verify that destroy() waits until the tasks finished timeout is reached', async () => {