From 86cbb7660561e416f4a59b6fe94bc4fcd6352ed1 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Thu, 21 Dec 2023 19:36:31 +0100 Subject: [PATCH] test: improve worker choice strategies coverage MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- tests/pools/abstract-pool.test.mjs | 80 ++++++++++++++++-------------- 1 file changed, 44 insertions(+), 36 deletions(-) diff --git a/tests/pools/abstract-pool.test.mjs b/tests/pools/abstract-pool.test.mjs index 9cc284d6..c0ba50b0 100644 --- a/tests/pools/abstract-pool.test.mjs +++ b/tests/pools/abstract-pool.test.mjs @@ -242,16 +242,18 @@ describe('Abstract pool test suite', () => { }) for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext .workerChoiceStrategies) { - expect(workerChoiceStrategy.opts).toStrictEqual( - expect.objectContaining({ - retries: - pool.info.maxSize + - Object.keys(workerChoiceStrategy.opts.weights).length, - runTime: { median: false }, - waitTime: { median: false }, - elu: { median: false } + expect(workerChoiceStrategy.opts).toStrictEqual({ + retries: + pool.info.maxSize + + Object.keys(workerChoiceStrategy.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) }) - ) + }) } await pool.destroy() const testHandler = () => console.info('test handler executed') @@ -482,16 +484,18 @@ describe('Abstract pool test suite', () => { }) for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext .workerChoiceStrategies) { - expect(workerChoiceStrategy.opts).toStrictEqual( - expect.objectContaining({ - retries: - pool.info.maxSize + - Object.keys(workerChoiceStrategy.opts.weights).length, - runTime: { median: false }, - waitTime: { median: false }, - elu: { median: false } + expect(workerChoiceStrategy.opts).toStrictEqual({ + retries: + pool.info.maxSize + + Object.keys(workerChoiceStrategy.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) }) - ) + }) } expect( pool.workerChoiceStrategyContext.getTaskStatisticsRequirements() @@ -534,16 +538,18 @@ describe('Abstract pool test suite', () => { }) for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext .workerChoiceStrategies) { - expect(workerChoiceStrategy.opts).toStrictEqual( - expect.objectContaining({ - retries: - pool.info.maxSize + - Object.keys(workerChoiceStrategy.opts.weights).length, - runTime: { median: true }, - waitTime: { median: false }, - elu: { median: true } + expect(workerChoiceStrategy.opts).toStrictEqual({ + retries: + pool.info.maxSize + + Object.keys(workerChoiceStrategy.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) }) - ) + }) } expect( pool.workerChoiceStrategyContext.getTaskStatisticsRequirements() @@ -586,16 +592,18 @@ describe('Abstract pool test suite', () => { }) for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext .workerChoiceStrategies) { - expect(workerChoiceStrategy.opts).toStrictEqual( - expect.objectContaining({ - retries: - pool.info.maxSize + - Object.keys(workerChoiceStrategy.opts.weights).length, - runTime: { median: false }, - waitTime: { median: false }, - elu: { median: false } + expect(workerChoiceStrategy.opts).toStrictEqual({ + retries: + pool.info.maxSize + + Object.keys(workerChoiceStrategy.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) }) - ) + }) } expect( pool.workerChoiceStrategyContext.getTaskStatisticsRequirements() -- 2.34.1