From 465b29401ecddad49070d3b0df4e55dc3902788c Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 30 Jun 2023 22:52:17 +0200 Subject: [PATCH] refactor: cleanup worker usage properties namespace 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 | 39 +++-- .../abstract-worker-choice-strategy.ts | 22 ++- .../least-busy-worker-choice-strategy.ts | 3 +- .../least-elu-worker-choice-strategy.ts | 2 +- .../least-used-worker-choice-strategy.ts | 2 +- src/pools/worker.ts | 2 +- src/utility-types.ts | 2 +- tests/pools/abstract/abstract-pool.test.js | 22 ++- tests/pools/cluster/fixed.test.js | 24 ++-- .../selection-strategies.test.js | 136 +++++++++--------- tests/pools/thread/fixed.test.js | 24 ++-- 11 files changed, 130 insertions(+), 148 deletions(-) diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index da0f2e77..71f765ac 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -246,41 +246,39 @@ export abstract class AbstractPool< workerNodes: this.workerNodes.length, idleWorkerNodes: this.workerNodes.reduce( (accumulator, workerNode) => - workerNode.workerUsage.tasks.executing === 0 + workerNode.usage.tasks.executing === 0 ? accumulator + 1 : accumulator, 0 ), busyWorkerNodes: this.workerNodes.reduce( (accumulator, workerNode) => - workerNode.workerUsage.tasks.executing > 0 - ? accumulator + 1 - : accumulator, + workerNode.usage.tasks.executing > 0 ? accumulator + 1 : accumulator, 0 ), executedTasks: this.workerNodes.reduce( (accumulator, workerNode) => - accumulator + workerNode.workerUsage.tasks.executed, + accumulator + workerNode.usage.tasks.executed, 0 ), executingTasks: this.workerNodes.reduce( (accumulator, workerNode) => - accumulator + workerNode.workerUsage.tasks.executing, + accumulator + workerNode.usage.tasks.executing, 0 ), queuedTasks: this.workerNodes.reduce( (accumulator, workerNode) => - accumulator + workerNode.workerUsage.tasks.queued, + accumulator + workerNode.usage.tasks.queued, 0 ), maxQueuedTasks: this.workerNodes.reduce( (accumulator, workerNode) => - accumulator + workerNode.workerUsage.tasks.maxQueued, + accumulator + workerNode.usage.tasks.maxQueued, 0 ), failedTasks: this.workerNodes.reduce( (accumulator, workerNode) => - accumulator + workerNode.workerUsage.tasks.failed, + accumulator + workerNode.usage.tasks.failed, 0 ) } @@ -312,7 +310,7 @@ export abstract class AbstractPool< * Gets the given worker its worker node key. * * @param worker - The worker. - * @returns The worker node key if the worker is found in the pool worker nodes, `-1` otherwise. + * @returns The worker node key if found in the pool worker nodes, `-1` otherwise. */ private getWorkerNodeKey (worker: Worker): number { return this.workerNodes.findIndex( @@ -408,7 +406,7 @@ export abstract class AbstractPool< protected internalBusy (): boolean { return ( this.workerNodes.findIndex(workerNode => { - return workerNode.workerUsage.tasks.executing === 0 + return workerNode.usage.tasks.executing === 0 }) === -1 ) } @@ -434,7 +432,7 @@ export abstract class AbstractPool< if ( this.opts.enableTasksQueue === true && (this.busy || - this.workerNodes[workerNodeKey].workerUsage.tasks.executing >= + this.workerNodes[workerNodeKey].usage.tasks.executing >= ((this.opts.tasksQueueOptions as TasksQueueOptions) .concurrency as number)) ) { @@ -491,7 +489,7 @@ export abstract class AbstractPool< workerNodeKey: number, task: Task ): void { - const workerUsage = this.workerNodes[workerNodeKey].workerUsage + const workerUsage = this.workerNodes[workerNodeKey].usage ++workerUsage.tasks.executing this.updateWaitTimeWorkerUsage(workerUsage, task) } @@ -507,8 +505,7 @@ export abstract class AbstractPool< worker: Worker, message: MessageValue ): void { - const workerUsage = - this.workerNodes[this.getWorkerNodeKey(worker)].workerUsage + const workerUsage = this.workerNodes[this.getWorkerNodeKey(worker)].usage this.updateTaskStatisticsWorkerUsage(workerUsage, message) this.updateRunTimeWorkerUsage(workerUsage, message) this.updateEluWorkerUsage(workerUsage, message) @@ -747,11 +744,9 @@ export abstract class AbstractPool< isKillBehavior(KillBehaviors.HARD, message.kill) || (message.kill != null && ((this.opts.enableTasksQueue === false && - this.workerNodes[workerNodeKey].workerUsage.tasks.executing === - 0) || + this.workerNodes[workerNodeKey].usage.tasks.executing === 0) || (this.opts.enableTasksQueue === true && - this.workerNodes[workerNodeKey].workerUsage.tasks.executing === - 0 && + this.workerNodes[workerNodeKey].usage.tasks.executing === 0 && this.tasksQueueSize(workerNodeKey) === 0))) ) { // Kill message received from the worker: no new tasks are submitted to that worker for a while ( > maxInactiveTime) @@ -819,7 +814,7 @@ export abstract class AbstractPool< workerNode: WorkerNode, workerUsage: WorkerUsage ): void { - workerNode.workerUsage = workerUsage + workerNode.usage = workerUsage } /** @@ -831,7 +826,7 @@ export abstract class AbstractPool< private pushWorkerNode (worker: Worker): number { this.workerNodes.push({ worker, - workerUsage: this.getWorkerUsage(), + usage: this.getWorkerUsage(), tasksQueue: new Queue>() }) const workerNodeKey = this.getWorkerNodeKey(worker) @@ -858,7 +853,7 @@ export abstract class AbstractPool< // ): void { // this.workerNodes[workerNodeKey] = { // worker, - // workerUsage, + // usage: workerUsage, // tasksQueue // } // } diff --git a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts index 37759198..cd969ccd 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -152,8 +152,8 @@ export abstract class AbstractWorkerChoiceStrategy< */ protected getWorkerTaskRunTime (workerNodeKey: number): number { return this.taskStatisticsRequirements.runTime.median - ? this.pool.workerNodes[workerNodeKey].workerUsage.runTime.median - : this.pool.workerNodes[workerNodeKey].workerUsage.runTime.average + ? this.pool.workerNodes[workerNodeKey].usage.runTime.median + : this.pool.workerNodes[workerNodeKey].usage.runTime.average } /** @@ -166,8 +166,8 @@ export abstract class AbstractWorkerChoiceStrategy< */ protected getWorkerTaskWaitTime (workerNodeKey: number): number { return this.taskStatisticsRequirements.waitTime.median - ? this.pool.workerNodes[workerNodeKey].workerUsage.waitTime.median - : this.pool.workerNodes[workerNodeKey].workerUsage.waitTime.average + ? this.pool.workerNodes[workerNodeKey].usage.waitTime.median + : this.pool.workerNodes[workerNodeKey].usage.waitTime.average } /** @@ -180,8 +180,8 @@ export abstract class AbstractWorkerChoiceStrategy< */ protected getWorkerTaskElu (workerNodeKey: number): number { return this.taskStatisticsRequirements.elu.median - ? this.pool.workerNodes[workerNodeKey].workerUsage.elu.active.median - : this.pool.workerNodes[workerNodeKey].workerUsage.elu.active.average + ? this.pool.workerNodes[workerNodeKey].usage.elu.active.median + : this.pool.workerNodes[workerNodeKey].usage.elu.active.average } protected computeDefaultWorkerWeight (): number { @@ -206,7 +206,7 @@ export abstract class AbstractWorkerChoiceStrategy< // */ // private findFirstFreeWorkerNodeKey (): number { // return this.pool.workerNodes.findIndex(workerNode => { - // return workerNode.workerUsage.tasks.executing === 0 + // return workerNode.usage.tasks.executing === 0 // }) // } @@ -221,17 +221,15 @@ export abstract class AbstractWorkerChoiceStrategy< // */ // private findLastFreeWorkerNodeKey (): number { // // It requires node >= 18.0.0: - // // return this.workerNodes.findLastIndex(workerNode => { - // // return workerNode.workerUsage.tasks.executing === 0 + // // return this.pool.workerNodes.findLastIndex(workerNode => { + // // return workerNode.usage.tasks.executing === 0 // // }) // for ( // let workerNodeKey = this.pool.workerNodes.length - 1; // workerNodeKey >= 0; // workerNodeKey-- // ) { - // if ( - // this.pool.workerNodes[workerNodeKey].workerUsage.tasks.executing === 0 - // ) { + // if (this.pool.workerNodes[workerNodeKey].usage.tasks.executing === 0) { // return workerNodeKey // } // } diff --git a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts index 7e9d5814..14aee44f 100644 --- a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts @@ -64,8 +64,7 @@ export class LeastBusyWorkerChoiceStrategy< let minTime = Infinity for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { const workerTime = - workerNode.workerUsage.runTime.aggregate + - workerNode.workerUsage.waitTime.aggregate + workerNode.usage.runTime.aggregate + workerNode.usage.waitTime.aggregate if (workerTime === 0) { this.nextWorkerNodeId = workerNodeKey break diff --git a/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts b/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts index 9c29a30a..cbe00a47 100644 --- a/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts @@ -59,7 +59,7 @@ export class LeastEluWorkerChoiceStrategy< public choose (): number { let minWorkerElu = Infinity for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { - const workerUsage = workerNode.workerUsage + const workerUsage = workerNode.usage const workerElu = workerUsage.elu?.active.aggregate ?? 0 if (workerElu === 0) { this.nextWorkerNodeId = workerNodeKey diff --git a/src/pools/selection-strategies/least-used-worker-choice-strategy.ts b/src/pools/selection-strategies/least-used-worker-choice-strategy.ts index 5c266f28..53aa05ee 100644 --- a/src/pools/selection-strategies/least-used-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-used-worker-choice-strategy.ts @@ -44,7 +44,7 @@ export class LeastUsedWorkerChoiceStrategy< public choose (): number { let minNumberOfTasks = Infinity for (const [workerNodeKey, workerNode] of this.pool.workerNodes.entries()) { - const workerTaskStatistics = workerNode.workerUsage.tasks + const workerTaskStatistics = workerNode.usage.tasks const workerTasks = workerTaskStatistics.executed + workerTaskStatistics.executing + diff --git a/src/pools/worker.ts b/src/pools/worker.ts index 07eabdfe..86f5121d 100644 --- a/src/pools/worker.ts +++ b/src/pools/worker.ts @@ -180,7 +180,7 @@ export interface WorkerNode { /** * Worker node worker usage statistics. */ - workerUsage: WorkerUsage + usage: WorkerUsage /** * Worker node tasks queue. */ diff --git a/src/utility-types.ts b/src/utility-types.ts index f330d192..1eb8df50 100644 --- a/src/utility-types.ts +++ b/src/utility-types.ts @@ -66,7 +66,7 @@ export interface MessageValue */ readonly taskPerformance?: TaskPerformance /** - * Whether to compute the given statistics or not. + * Whether the worker computes the given statistics or not. */ readonly statistics?: WorkerStatistics } diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index b5a53487..424ad352 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -432,7 +432,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) } @@ -450,7 +450,7 @@ 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, @@ -515,7 +515,7 @@ 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, @@ -554,7 +554,7 @@ 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: maxMultiplier, executing: 0, @@ -607,7 +607,7 @@ 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, @@ -643,14 +643,12 @@ describe('Abstract pool test suite', () => { 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, @@ -686,8 +684,8 @@ describe('Abstract pool test suite', () => { 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() }) diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index 8f3fad8b..631c59f0 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -96,12 +96,12 @@ describe('Fixed cluster pool test suite', () => { } expect(promises.size).toBe(numberOfWorkers * maxMultiplier) for (const workerNode of queuePool.workerNodes) { - expect(workerNode.workerUsage.tasks.executing).toBeLessThanOrEqual( + expect(workerNode.usage.tasks.executing).toBeLessThanOrEqual( queuePool.opts.tasksQueueOptions.concurrency ) - expect(workerNode.workerUsage.tasks.executed).toBe(0) - expect(workerNode.workerUsage.tasks.queued).toBeGreaterThan(0) - expect(workerNode.workerUsage.tasks.maxQueued).toBeGreaterThan(0) + expect(workerNode.usage.tasks.executed).toBe(0) + expect(workerNode.usage.tasks.queued).toBeGreaterThan(0) + expect(workerNode.usage.tasks.maxQueued).toBeGreaterThan(0) } expect(queuePool.info.executingTasks).toBe(numberOfWorkers) expect(queuePool.info.queuedTasks).toBe( @@ -112,13 +112,11 @@ describe('Fixed cluster pool test suite', () => { ) await Promise.all(promises) for (const workerNode of queuePool.workerNodes) { - expect(workerNode.workerUsage.tasks.executing).toBe(0) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThan(0) - expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( - maxMultiplier - ) - expect(workerNode.workerUsage.tasks.queued).toBe(0) - expect(workerNode.workerUsage.tasks.maxQueued).toBe(1) + expect(workerNode.usage.tasks.executing).toBe(0) + expect(workerNode.usage.tasks.executed).toBeGreaterThan(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(maxMultiplier) + expect(workerNode.usage.tasks.queued).toBe(0) + expect(workerNode.usage.tasks.maxQueued).toBe(1) } }) @@ -154,7 +152,7 @@ describe('Fixed cluster pool test suite', () => { }) expect( errorPool.workerNodes.some( - workerNode => workerNode.workerUsage.tasks.failed === 1 + workerNode => workerNode.usage.tasks.failed === 1 ) ).toBe(true) }) @@ -180,7 +178,7 @@ describe('Fixed cluster pool test suite', () => { }) expect( asyncErrorPool.workerNodes.some( - workerNode => workerNode.workerUsage.tasks.failed === 1 + workerNode => workerNode.usage.tasks.failed === 1 ) ).toBe(true) }) diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index dd5a398f..b2aa4a0b 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -209,7 +209,7 @@ describe('Selection strategies test suite', () => { } await Promise.all(promises) for (const workerNode of pool.workerNodes) { - expect(workerNode.workerUsage).toStrictEqual({ + expect(workerNode.usage).toStrictEqual({ tasks: { executed: maxMultiplier, executing: 0, @@ -270,7 +270,7 @@ describe('Selection strategies test suite', () => { } await Promise.all(promises) for (const workerNode of pool.workerNodes) { - expect(workerNode.workerUsage).toStrictEqual({ + expect(workerNode.usage).toStrictEqual({ tasks: { executed: maxMultiplier, executing: 0, @@ -476,7 +476,7 @@ describe('Selection strategies 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, @@ -512,8 +512,8 @@ describe('Selection strategies test suite', () => { utilization: 0 } }) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) } @@ -536,7 +536,7 @@ describe('Selection strategies 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, @@ -572,8 +572,8 @@ describe('Selection strategies test suite', () => { utilization: 0 } }) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) } @@ -675,7 +675,7 @@ describe('Selection strategies 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, @@ -711,14 +711,12 @@ describe('Selection strategies test suite', () => { utilization: 0 } }) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) - expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.waitTime.aggregate).toBeGreaterThanOrEqual( - 0 - ) + expect(workerNode.usage.runTime.aggregate).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.waitTime.aggregate).toBeGreaterThanOrEqual(0) } // We need to clean up the resources after our test await pool.destroy() @@ -739,7 +737,7 @@ describe('Selection strategies 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, @@ -775,14 +773,12 @@ describe('Selection strategies test suite', () => { utilization: 0 } }) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) - expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.waitTime.aggregate).toBeGreaterThanOrEqual( - 0 - ) + expect(workerNode.usage.runTime.aggregate).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.waitTime.aggregate).toBeGreaterThanOrEqual(0) } // We need to clean up the resources after our test await pool.destroy() @@ -882,7 +878,7 @@ describe('Selection strategies 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, @@ -918,12 +914,12 @@ describe('Selection strategies test suite', () => { utilization: expect.any(Number) } }) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) - expect(workerNode.workerUsage.elu.utilization).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.elu.utilization).toBeLessThanOrEqual(1) + expect(workerNode.usage.elu.utilization).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.elu.utilization).toBeLessThanOrEqual(1) } // We need to clean up the resources after our test await pool.destroy() @@ -944,7 +940,7 @@ describe('Selection strategies 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, @@ -980,12 +976,12 @@ describe('Selection strategies test suite', () => { utilization: expect.any(Number) } }) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) - expect(workerNode.workerUsage.elu.utilization).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.elu.utilization).toBeLessThanOrEqual(1) + expect(workerNode.usage.elu.utilization).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.elu.utilization).toBeLessThanOrEqual(1) } // We need to clean up the resources after our test await pool.destroy() @@ -1085,7 +1081,7 @@ describe('Selection strategies 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, @@ -1121,14 +1117,14 @@ describe('Selection strategies test suite', () => { utilization: expect.any(Number) } }) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) - 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) + expect(workerNode.usage.runTime.aggregate).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.runTime.average).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.elu.utilization).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.elu.utilization).toBeLessThanOrEqual(1) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1154,7 +1150,7 @@ describe('Selection strategies 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, @@ -1190,14 +1186,14 @@ describe('Selection strategies test suite', () => { utilization: expect.any(Number) } }) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) - 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) + expect(workerNode.usage.runTime.aggregate).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.runTime.average).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.elu.utilization).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.elu.utilization).toBeLessThanOrEqual(1) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1228,7 +1224,7 @@ describe('Selection strategies 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, @@ -1264,14 +1260,14 @@ describe('Selection strategies test suite', () => { utilization: expect.any(Number) } }) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) - expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.runTime.median).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.elu.utilization).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.elu.utilization).toBeLessThanOrEqual(1) + expect(workerNode.usage.runTime.aggregate).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.runTime.median).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.elu.utilization).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.elu.utilization).toBeLessThanOrEqual(1) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1450,7 +1446,7 @@ describe('Selection strategies 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, @@ -1486,12 +1482,12 @@ describe('Selection strategies test suite', () => { utilization: 0 } }) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) - expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.runTime.average).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.runTime.aggregate).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.runTime.average).toBeGreaterThanOrEqual(0) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1522,7 +1518,7 @@ describe('Selection strategies 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, @@ -1558,12 +1554,12 @@ describe('Selection strategies test suite', () => { utilization: 0 } }) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) - expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThan(0) - expect(workerNode.workerUsage.runTime.average).toBeGreaterThan(0) + expect(workerNode.usage.runTime.aggregate).toBeGreaterThan(0) + expect(workerNode.usage.runTime.average).toBeGreaterThan(0) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1599,7 +1595,7 @@ describe('Selection strategies 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, @@ -1635,12 +1631,12 @@ describe('Selection strategies test suite', () => { utilization: 0 } }) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThanOrEqual(0) - expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( + expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( max * maxMultiplier ) - expect(workerNode.workerUsage.runTime.aggregate).toBeGreaterThan(0) - expect(workerNode.workerUsage.runTime.median).toBeGreaterThan(0) + expect(workerNode.usage.runTime.aggregate).toBeGreaterThan(0) + expect(workerNode.usage.runTime.median).toBeGreaterThan(0) } expect( pool.workerChoiceStrategyContext.workerChoiceStrategies.get( @@ -1833,7 +1829,7 @@ describe('Selection strategies test suite', () => { } await Promise.all(promises) for (const workerNode of pool.workerNodes) { - expect(workerNode.workerUsage).toStrictEqual({ + expect(workerNode.usage).toStrictEqual({ tasks: { executed: maxMultiplier, executing: 0, @@ -1916,7 +1912,7 @@ describe('Selection strategies test suite', () => { } await Promise.all(promises) for (const workerNode of pool.workerNodes) { - expect(workerNode.workerUsage).toStrictEqual({ + expect(workerNode.usage).toStrictEqual({ tasks: { executed: maxMultiplier, executing: 0, diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index 017cd7e3..e5d9831d 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -96,12 +96,12 @@ describe('Fixed thread pool test suite', () => { } expect(promises.size).toBe(numberOfThreads * maxMultiplier) for (const workerNode of queuePool.workerNodes) { - expect(workerNode.workerUsage.tasks.executing).toBeLessThanOrEqual( + expect(workerNode.usage.tasks.executing).toBeLessThanOrEqual( queuePool.opts.tasksQueueOptions.concurrency ) - expect(workerNode.workerUsage.tasks.executed).toBe(0) - expect(workerNode.workerUsage.tasks.queued).toBeGreaterThan(0) - expect(workerNode.workerUsage.tasks.maxQueued).toBeGreaterThan(0) + expect(workerNode.usage.tasks.executed).toBe(0) + expect(workerNode.usage.tasks.queued).toBeGreaterThan(0) + expect(workerNode.usage.tasks.maxQueued).toBeGreaterThan(0) } expect(queuePool.info.executingTasks).toBe(numberOfThreads) expect(queuePool.info.queuedTasks).toBe( @@ -112,13 +112,11 @@ describe('Fixed thread pool test suite', () => { ) await Promise.all(promises) for (const workerNode of queuePool.workerNodes) { - expect(workerNode.workerUsage.tasks.executing).toBe(0) - expect(workerNode.workerUsage.tasks.executed).toBeGreaterThan(0) - expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual( - maxMultiplier - ) - expect(workerNode.workerUsage.tasks.queued).toBe(0) - expect(workerNode.workerUsage.tasks.maxQueued).toBe(1) + expect(workerNode.usage.tasks.executing).toBe(0) + expect(workerNode.usage.tasks.executed).toBeGreaterThan(0) + expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(maxMultiplier) + expect(workerNode.usage.tasks.queued).toBe(0) + expect(workerNode.usage.tasks.maxQueued).toBe(1) } }) @@ -156,7 +154,7 @@ describe('Fixed thread pool test suite', () => { }) expect( errorPool.workerNodes.some( - workerNode => workerNode.workerUsage.tasks.failed === 1 + workerNode => workerNode.usage.tasks.failed === 1 ) ).toBe(true) }) @@ -184,7 +182,7 @@ describe('Fixed thread pool test suite', () => { }) expect( asyncErrorPool.workerNodes.some( - workerNode => workerNode.workerUsage.tasks.failed === 1 + workerNode => workerNode.usage.tasks.failed === 1 ) ).toBe(true) }) -- 2.34.1