From 76407b8eb2e0e19b7861526eaa61bb80cd864199 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sat, 17 Jun 2023 15:01:23 +0200 Subject: [PATCH] fix: updates strategies internals once statistics are computed MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/abstract-pool.ts | 1 - .../selection-strategies-types.ts | 2 +- .../selection-strategies.test.js | 26 +++++++++++++------ 3 files changed, 19 insertions(+), 10 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 1341c9af..a042e873 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -421,7 +421,6 @@ export abstract class AbstractPool< } else { this.executeTask(workerNodeKey, submittedTask) } - this.workerChoiceStrategyContext.update(workerNodeKey) this.checkAndEmitEvents() // eslint-disable-next-line @typescript-eslint/return-await return res diff --git a/src/pools/selection-strategies/selection-strategies-types.ts b/src/pools/selection-strategies/selection-strategies-types.ts index 7a5a10c6..ac2ee6c3 100644 --- a/src/pools/selection-strategies/selection-strategies-types.ts +++ b/src/pools/selection-strategies/selection-strategies-types.ts @@ -147,7 +147,7 @@ export interface TaskStatisticsRequirements { */ export interface StrategyPolicy { /** - * Expect direct usage of dynamic worker. + * Expects direct usage of dynamic worker. */ useDynamicWorker: boolean } diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index d7567114..6091bf08 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -476,7 +476,7 @@ describe('Selection strategies test suite', () => { for (const workerNode of pool.workerNodes) { expect(workerNode.workerUsage).toStrictEqual({ tasks: { - executed: maxMultiplier, + executed: expect.any(Number), executing: 0, queued: 0, failed: 0 @@ -509,6 +509,10 @@ describe('Selection strategies test suite', () => { utilization: 0 } }) + expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + max * maxMultiplier + ) } // We need to clean up the resources after our test await pool.destroy() @@ -531,7 +535,7 @@ describe('Selection strategies test suite', () => { for (const workerNode of pool.workerNodes) { expect(workerNode.workerUsage).toStrictEqual({ tasks: { - executed: maxMultiplier, + executed: expect.any(Number), executing: 0, queued: 0, failed: 0 @@ -564,6 +568,10 @@ describe('Selection strategies test suite', () => { utilization: 0 } }) + expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + max * maxMultiplier + ) } // We need to clean up the resources after our test await pool.destroy() @@ -698,7 +706,7 @@ describe('Selection strategies test suite', () => { utilization: 0 } }) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThan(0) + expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) @@ -761,12 +769,14 @@ describe('Selection strategies test suite', () => { utilization: 0 } }) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThan(0) + expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) - expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThan(0) - expect(workerNode.workerUsage.waitTime.aggregate).toBeGreaterThan(0) + expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.waitTime.aggregate).toBeGreaterThanOrEqual( + 0 + ) } // We need to clean up the resources after our test await pool.destroy() @@ -1106,8 +1116,8 @@ describe('Selection strategies test suite', () => { expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) - expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThan(0) - expect(workerNode.workerUsage.runTime.average).toBeGreaterThan(0) + expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThanOrEqual(0) + expect(workerNode.workerUsage.runTime.average).toBeGreaterThanOrEqual(0) expect(workerNode.workerUsage.elu.utilization).toBeGreaterThanOrEqual(0) expect(workerNode.workerUsage.elu.utilization).toBeLessThanOrEqual(1) } -- 2.34.1