From 8d3efca6e146993ce209d73f783d3adb1dbf5363 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 8 Jul 2025 20:30:49 +0200 Subject: [PATCH] refactor: add worker strategy name to help UTs debug MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- biome.json | 2 +- package.json | 4 +- pnpm-lock.yaml | 102 +++++++++--------- .../abstract-worker-choice-strategy.ts | 4 + .../fair-share-worker-choice-strategy.ts | 5 + ...hted-round-robin-worker-choice-strategy.ts | 16 ++- .../least-busy-worker-choice-strategy.ts | 15 ++- .../least-elu-worker-choice-strategy.ts | 15 ++- .../least-used-worker-choice-strategy.ts | 13 ++- .../round-robin-worker-choice-strategy.ts | 14 ++- .../selection-strategies-types.ts | 4 + ...hted-round-robin-worker-choice-strategy.ts | 16 ++- .../worker-choice-strategies-context.ts | 2 +- .../selection-strategies.test.mjs | 5 + .../worker-choice-strategies-context.test.mjs | 4 +- 15 files changed, 136 insertions(+), 85 deletions(-) diff --git a/biome.json b/biome.json index 8fa568df4..ccae666b6 100644 --- a/biome.json +++ b/biome.json @@ -1,5 +1,5 @@ { - "$schema": "https://biomejs.dev/schemas/2.1.0/schema.json", + "$schema": "https://biomejs.dev/schemas/2.1.1/schema.json", "assist": { "actions": { "source": { "organizeImports": "off" } } }, "linter": { "enabled": false, diff --git a/package.json b/package.json index 1dc9e2bee..e773857d2 100644 --- a/package.json +++ b/package.json @@ -106,7 +106,7 @@ } }, "devDependencies": { - "@biomejs/biome": "^2.1.0", + "@biomejs/biome": "^2.1.1", "@commitlint/cli": "^19.8.1", "@commitlint/config-conventional": "^19.8.1", "@cspell/eslint-plugin": "^9.1.3", @@ -114,7 +114,7 @@ "@rollup/plugin-terser": "^0.4.4", "@rollup/plugin-typescript": "^12.1.4", "@std/expect": "npm:@jsr/std__expect@^1.0.16", - "@types/node": "^24.0.10", + "@types/node": "^24.0.11", "c8": "^10.1.3", "clean-publish": "^5.2.2", "cross-env": "^7.0.3", diff --git a/pnpm-lock.yaml b/pnpm-lock.yaml index e4b830203..8437ca252 100644 --- a/pnpm-lock.yaml +++ b/pnpm-lock.yaml @@ -12,11 +12,11 @@ importers: .: devDependencies: '@biomejs/biome': - specifier: ^2.1.0 - version: 2.1.0 + specifier: ^2.1.1 + version: 2.1.1 '@commitlint/cli': specifier: ^19.8.1 - version: 19.8.1(@types/node@24.0.10)(typescript@5.8.3) + version: 19.8.1(@types/node@24.0.11)(typescript@5.8.3) '@commitlint/config-conventional': specifier: ^19.8.1 version: 19.8.1 @@ -36,8 +36,8 @@ importers: specifier: npm:@jsr/std__expect@^1.0.16 version: '@jsr/std__expect@1.0.16' '@types/node': - specifier: ^24.0.10 - version: 24.0.10 + specifier: ^24.0.11 + version: 24.0.11 c8: specifier: ^10.1.3 version: 10.1.3 @@ -120,55 +120,55 @@ packages: resolution: {integrity: sha512-6zABk/ECA/QYSCQ1NGiVwwbQerUCZ+TQbp64Q3AgmfNvurHH0j8TtXa1qbShXA6qqkpAj4V5W8pP6mLe1mcMqA==} engines: {node: '>=18'} - '@biomejs/biome@2.1.0': - resolution: {integrity: sha512-K2UDr1dCiaOWegp4yQLMC4Evgl85ze1O7r+WxPeO7cNl0XrIcTshvdQGMDB23c/2afXz6RsOKYfWLErNbBbjmA==} + '@biomejs/biome@2.1.1': + resolution: {integrity: sha512-HFGYkxG714KzG+8tvtXCJ1t1qXQMzgWzfvQaUjxN6UeKv+KvMEuliInnbZLJm6DXFXwqVi6446EGI0sGBLIYng==} engines: {node: '>=14.21.3'} hasBin: true - '@biomejs/cli-darwin-arm64@2.1.0': - resolution: {integrity: sha512-RDXEUGSCvUx3PKWRt95WRtwH+l01slm7r2zaotDwWERn/RITMcdet21rI5q5cYhL4XJiAvLHG8qyLNSXqIOCwQ==} + '@biomejs/cli-darwin-arm64@2.1.1': + resolution: {integrity: sha512-2Muinu5ok4tWxq4nu5l19el48cwCY/vzvI7Vjbkf3CYIQkjxZLyj0Ad37Jv2OtlXYaLvv+Sfu1hFeXt/JwRRXQ==} engines: {node: '>=14.21.3'} cpu: [arm64] os: [darwin] - '@biomejs/cli-darwin-x64@2.1.0': - resolution: {integrity: sha512-epLFRbMjYS/Cu9Kc5gM3wzUExsKj2Z0oxIiuxlI4ZterIqm19yvTOtJoqSec8gjUXOTNvPVoEIfSSXg37yepow==} + '@biomejs/cli-darwin-x64@2.1.1': + resolution: {integrity: sha512-cC8HM5lrgKQXLAK+6Iz2FrYW5A62pAAX6KAnRlEyLb+Q3+Kr6ur/sSuoIacqlp1yvmjHJqjYfZjPvHWnqxoEIA==} engines: {node: '>=14.21.3'} cpu: [x64] os: [darwin] - '@biomejs/cli-linux-arm64-musl@2.1.0': - resolution: {integrity: sha512-J7z6s/M50wt5lhSkivAs2GJHPhiah3hkdg1LipM6wlK6cVC3YeIA/X6pgWBfjEwyfsFlpc3nRM+pQ17DI8FpDQ==} + '@biomejs/cli-linux-arm64-musl@2.1.1': + resolution: {integrity: sha512-/7FBLnTswu4jgV9ttI3AMIdDGqVEPIZd8I5u2D4tfCoj8rl9dnjrEQbAIDlWhUXdyWlFSz8JypH3swU9h9P+2A==} engines: {node: '>=14.21.3'} cpu: [arm64] os: [linux] - '@biomejs/cli-linux-arm64@2.1.0': - resolution: {integrity: sha512-HZys1/TeIH5lagwtf9yKSO+gtA+cYMJW22ckDGuKt2xIvPu7VqgTNjJtTdRcetXe0+benlMMo+KFs3xL2b/2QA==} + '@biomejs/cli-linux-arm64@2.1.1': + resolution: {integrity: sha512-tw4BEbhAUkWPe4WBr6IX04DJo+2jz5qpPzpW/SWvqMjb9QuHY8+J0M23V8EPY/zWU4IG8Ui0XESapR1CB49Q7g==} engines: {node: '>=14.21.3'} cpu: [arm64] os: [linux] - '@biomejs/cli-linux-x64-musl@2.1.0': - resolution: {integrity: sha512-uj8felYcBeXh32kznnKrAQoZ9pLqta/6qvwLJ4AZtUmY6cSUUa5c+VLnFtxMfuhvps/M4D55VGnwSINOEblPQg==} + '@biomejs/cli-linux-x64-musl@2.1.1': + resolution: {integrity: sha512-kUu+loNI3OCD2c12cUt7M5yaaSjDnGIksZwKnueubX6c/HWUyi/0mPbTBHR49Me3F0KKjWiKM+ZOjsmC+lUt9g==} engines: {node: '>=14.21.3'} cpu: [x64] os: [linux] - '@biomejs/cli-linux-x64@2.1.0': - resolution: {integrity: sha512-nAVAP1ov/zcXMhNq3WCbYZmlU/YTF3ZT+LeXR1CEJnDgunPC/Srp7j1LWlrIx6wxNOCDOFow8fmyfC7c/BKLig==} + '@biomejs/cli-linux-x64@2.1.1': + resolution: {integrity: sha512-3WJ1GKjU7NzZb6RTbwLB59v9cTIlzjbiFLDB0z4376TkDqoNYilJaC37IomCr/aXwuU8QKkrYoHrgpSq5ffJ4Q==} engines: {node: '>=14.21.3'} cpu: [x64] os: [linux] - '@biomejs/cli-win32-arm64@2.1.0': - resolution: {integrity: sha512-eGGqGs+8Q34n1zp/rEadFRKjzwFszpZ2+p6B1Dmi7dn1DNEYhNXoRWLcjyca+ZSTrdV7COx0scyjgF9Tg73kBw==} + '@biomejs/cli-win32-arm64@2.1.1': + resolution: {integrity: sha512-vEHK0v0oW+E6RUWLoxb2isI3rZo57OX9ZNyyGH701fZPj6Il0Rn1f5DMNyCmyflMwTnIQstEbs7n2BxYSqQx4Q==} engines: {node: '>=14.21.3'} cpu: [arm64] os: [win32] - '@biomejs/cli-win32-x64@2.1.0': - resolution: {integrity: sha512-pkp6jucyvE8DJSXXwSKs+Mxx1KXkMJ2d8GbBu4Lf0nAQHl40TZjjp1RuNEo9Z7NNXPQzbLACDtK6/vDalO2WRg==} + '@biomejs/cli-win32-x64@2.1.1': + resolution: {integrity: sha512-i2PKdn70kY++KEF/zkQFvQfX1e8SkA8hq4BgC+yE9dZqyLzB/XStY2MvwI3qswlRgnGpgncgqe0QYKVS1blksg==} engines: {node: '>=14.21.3'} cpu: [x64] os: [win32] @@ -795,8 +795,8 @@ packages: '@types/json-schema@7.0.15': resolution: {integrity: sha512-5+fP8P8MFNC+AyZCDxrB2pkZFPGzqQWUzpSeuuVLvm8VMcorNYavBqoFcxK8bQz4Qsbn4oUEEem4wDLfcysGHA==} - '@types/node@24.0.10': - resolution: {integrity: sha512-ENHwaH+JIRTDIEEbDK6QSQntAYGtbvdDXnMXnZaZ6k13Du1dPMmprkEHIL7ok2Wl2aZevetwTAb5S+7yIF+enA==} + '@types/node@24.0.11': + resolution: {integrity: sha512-CJV8eqrYnwQJGMrvcRhQmZfpyniDavB+7nAZYJc6w99hFYJyFN3INV1/2W3QfQrqM36WTLrijJ1fxxvGBmCSxA==} '@types/unist@3.0.3': resolution: {integrity: sha512-ko/gIFJRv177XgZsZcBwnqJN5x/Gien8qNOn0D5bQU/zAzVf9Zt3BlcUiLqhV9y4ARk0GbT3tnUiPNgnTXzc/Q==} @@ -2809,46 +2809,46 @@ snapshots: '@bcoe/v8-coverage@1.0.2': {} - '@biomejs/biome@2.1.0': + '@biomejs/biome@2.1.1': optionalDependencies: - '@biomejs/cli-darwin-arm64': 2.1.0 - '@biomejs/cli-darwin-x64': 2.1.0 - '@biomejs/cli-linux-arm64': 2.1.0 - '@biomejs/cli-linux-arm64-musl': 2.1.0 - '@biomejs/cli-linux-x64': 2.1.0 - '@biomejs/cli-linux-x64-musl': 2.1.0 - '@biomejs/cli-win32-arm64': 2.1.0 - '@biomejs/cli-win32-x64': 2.1.0 - - '@biomejs/cli-darwin-arm64@2.1.0': + '@biomejs/cli-darwin-arm64': 2.1.1 + '@biomejs/cli-darwin-x64': 2.1.1 + '@biomejs/cli-linux-arm64': 2.1.1 + '@biomejs/cli-linux-arm64-musl': 2.1.1 + '@biomejs/cli-linux-x64': 2.1.1 + '@biomejs/cli-linux-x64-musl': 2.1.1 + '@biomejs/cli-win32-arm64': 2.1.1 + '@biomejs/cli-win32-x64': 2.1.1 + + '@biomejs/cli-darwin-arm64@2.1.1': optional: true - '@biomejs/cli-darwin-x64@2.1.0': + '@biomejs/cli-darwin-x64@2.1.1': optional: true - '@biomejs/cli-linux-arm64-musl@2.1.0': + '@biomejs/cli-linux-arm64-musl@2.1.1': optional: true - '@biomejs/cli-linux-arm64@2.1.0': + '@biomejs/cli-linux-arm64@2.1.1': optional: true - '@biomejs/cli-linux-x64-musl@2.1.0': + '@biomejs/cli-linux-x64-musl@2.1.1': optional: true - '@biomejs/cli-linux-x64@2.1.0': + '@biomejs/cli-linux-x64@2.1.1': optional: true - '@biomejs/cli-win32-arm64@2.1.0': + '@biomejs/cli-win32-arm64@2.1.1': optional: true - '@biomejs/cli-win32-x64@2.1.0': + '@biomejs/cli-win32-x64@2.1.1': optional: true - '@commitlint/cli@19.8.1(@types/node@24.0.10)(typescript@5.8.3)': + '@commitlint/cli@19.8.1(@types/node@24.0.11)(typescript@5.8.3)': dependencies: '@commitlint/format': 19.8.1 '@commitlint/lint': 19.8.1 - '@commitlint/load': 19.8.1(@types/node@24.0.10)(typescript@5.8.3) + '@commitlint/load': 19.8.1(@types/node@24.0.11)(typescript@5.8.3) '@commitlint/read': 19.8.1 '@commitlint/types': 19.8.1 tinyexec: 1.0.1 @@ -2895,7 +2895,7 @@ snapshots: '@commitlint/rules': 19.8.1 '@commitlint/types': 19.8.1 - '@commitlint/load@19.8.1(@types/node@24.0.10)(typescript@5.8.3)': + '@commitlint/load@19.8.1(@types/node@24.0.11)(typescript@5.8.3)': dependencies: '@commitlint/config-validator': 19.8.1 '@commitlint/execute-rule': 19.8.1 @@ -2903,7 +2903,7 @@ snapshots: '@commitlint/types': 19.8.1 chalk: 5.4.1 cosmiconfig: 9.0.0(typescript@5.8.3) - cosmiconfig-typescript-loader: 6.1.0(@types/node@24.0.10)(cosmiconfig@9.0.0(typescript@5.8.3))(typescript@5.8.3) + cosmiconfig-typescript-loader: 6.1.0(@types/node@24.0.11)(cosmiconfig@9.0.0(typescript@5.8.3))(typescript@5.8.3) lodash.isplainobject: 4.0.6 lodash.merge: 4.6.2 lodash.uniq: 4.5.0 @@ -3477,7 +3477,7 @@ snapshots: '@types/conventional-commits-parser@5.0.1': dependencies: - '@types/node': 24.0.10 + '@types/node': 24.0.11 '@types/estree@1.0.8': {} @@ -3489,7 +3489,7 @@ snapshots: '@types/json-schema@7.0.15': {} - '@types/node@24.0.10': + '@types/node@24.0.11': dependencies: undici-types: 7.8.0 @@ -3896,9 +3896,9 @@ snapshots: core-util-is@1.0.3: {} - cosmiconfig-typescript-loader@6.1.0(@types/node@24.0.10)(cosmiconfig@9.0.0(typescript@5.8.3))(typescript@5.8.3): + cosmiconfig-typescript-loader@6.1.0(@types/node@24.0.11)(cosmiconfig@9.0.0(typescript@5.8.3))(typescript@5.8.3): dependencies: - '@types/node': 24.0.10 + '@types/node': 24.0.11 cosmiconfig: 9.0.0(typescript@5.8.3) jiti: 2.4.2 typescript: 5.8.3 diff --git a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts index 68d91ed34..8814c7121 100644 --- a/src/pools/selection-strategies/abstract-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/abstract-worker-choice-strategy.ts @@ -4,6 +4,7 @@ import type { IWorkerChoiceStrategy, StrategyPolicy, TaskStatisticsRequirements, + WorkerChoiceStrategy, WorkerChoiceStrategyOptions, } from './selection-strategies-types.js' @@ -24,6 +25,9 @@ export abstract class AbstractWorkerChoiceStrategy< Data = unknown, Response = unknown > implements IWorkerChoiceStrategy { + /** @inheritDoc */ + public abstract readonly name: WorkerChoiceStrategy + /** @inheritDoc */ public readonly strategyPolicy: StrategyPolicy = Object.freeze({ dynamicWorkerReady: true, diff --git a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts index e5e07ecd1..f4d707e94 100644 --- a/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/fair-share-worker-choice-strategy.ts @@ -6,6 +6,8 @@ import { type IWorkerChoiceStrategy, Measurements, type TaskStatisticsRequirements, + WorkerChoiceStrategies, + type WorkerChoiceStrategy, type WorkerChoiceStrategyOptions, } from './selection-strategies-types.js' @@ -23,6 +25,9 @@ export class FairShareWorkerChoiceStrategy< > extends AbstractWorkerChoiceStrategy implements IWorkerChoiceStrategy { + /** @inheritDoc */ + public readonly name: WorkerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE + /** @inheritDoc */ public override readonly taskStatisticsRequirements: TaskStatisticsRequirements = Object.freeze({ diff --git a/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts index 7c37685fa..175653c3a 100644 --- a/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.ts @@ -1,13 +1,15 @@ import type { IPool } from '../pool.js' import type { IWorker } from '../worker.js' -import type { - IWorkerChoiceStrategy, - TaskStatisticsRequirements, - WorkerChoiceStrategyOptions, -} from './selection-strategies-types.js' import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../utils.js' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js' +import { + type IWorkerChoiceStrategy, + type TaskStatisticsRequirements, + WorkerChoiceStrategies, + type WorkerChoiceStrategy, + type WorkerChoiceStrategyOptions, +} from './selection-strategies-types.js' /** * Selects the next worker with an interleaved weighted round robin scheduling algorithm. @@ -22,6 +24,10 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy< > extends AbstractWorkerChoiceStrategy implements IWorkerChoiceStrategy { + /** @inheritDoc */ + public readonly name: WorkerChoiceStrategy = + WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN + /** @inheritDoc */ public override readonly taskStatisticsRequirements: TaskStatisticsRequirements = Object.freeze({ 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 cba9e17ee..bc22a3dc6 100644 --- a/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-busy-worker-choice-strategy.ts @@ -1,13 +1,15 @@ import type { IPool } from '../pool.js' import type { IWorker } from '../worker.js' -import type { - IWorkerChoiceStrategy, - TaskStatisticsRequirements, - WorkerChoiceStrategyOptions, -} from './selection-strategies-types.js' import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../utils.js' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js' +import { + type IWorkerChoiceStrategy, + type TaskStatisticsRequirements, + WorkerChoiceStrategies, + type WorkerChoiceStrategy, + type WorkerChoiceStrategyOptions, +} from './selection-strategies-types.js' /** * Selects the least busy worker. @@ -22,6 +24,9 @@ export class LeastBusyWorkerChoiceStrategy< > extends AbstractWorkerChoiceStrategy implements IWorkerChoiceStrategy { + /** @inheritDoc */ + public readonly name: WorkerChoiceStrategy = WorkerChoiceStrategies.LEAST_BUSY + /** @inheritDoc */ public override readonly taskStatisticsRequirements: TaskStatisticsRequirements = Object.freeze({ 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 5a52a280a..9ee3090f6 100644 --- a/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-elu-worker-choice-strategy.ts @@ -1,13 +1,15 @@ import type { IPool } from '../pool.js' import type { IWorker } from '../worker.js' -import type { - IWorkerChoiceStrategy, - TaskStatisticsRequirements, - WorkerChoiceStrategyOptions, -} from './selection-strategies-types.js' import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../utils.js' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js' +import { + type IWorkerChoiceStrategy, + type TaskStatisticsRequirements, + WorkerChoiceStrategies, + type WorkerChoiceStrategy, + type WorkerChoiceStrategyOptions, +} from './selection-strategies-types.js' /** * Selects the worker with the least ELU. @@ -22,6 +24,9 @@ export class LeastEluWorkerChoiceStrategy< > extends AbstractWorkerChoiceStrategy implements IWorkerChoiceStrategy { + /** @inheritDoc */ + public readonly name: WorkerChoiceStrategy = WorkerChoiceStrategies.LEAST_ELU + /** @inheritDoc */ public override readonly taskStatisticsRequirements: TaskStatisticsRequirements = Object.freeze({ 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 5d877ba9a..13e6dd33e 100644 --- a/src/pools/selection-strategies/least-used-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/least-used-worker-choice-strategy.ts @@ -1,11 +1,13 @@ import type { IPool } from '../pool.js' import type { IWorker } from '../worker.js' -import type { - IWorkerChoiceStrategy, - WorkerChoiceStrategyOptions, -} from './selection-strategies-types.js' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js' +import { + type IWorkerChoiceStrategy, + WorkerChoiceStrategies, + type WorkerChoiceStrategy, + type WorkerChoiceStrategyOptions, +} from './selection-strategies-types.js' /** * Selects the least used worker. @@ -20,6 +22,9 @@ export class LeastUsedWorkerChoiceStrategy< > extends AbstractWorkerChoiceStrategy implements IWorkerChoiceStrategy { + /** @inheritDoc */ + public readonly name: WorkerChoiceStrategy = WorkerChoiceStrategies.LEAST_USED + /** @inheritDoc */ public constructor ( pool: IPool, diff --git a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts index 5967f5493..0ec031374 100644 --- a/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/round-robin-worker-choice-strategy.ts @@ -1,11 +1,13 @@ import type { IPool } from '../pool.js' import type { IWorker } from '../worker.js' -import type { - IWorkerChoiceStrategy, - WorkerChoiceStrategyOptions, -} from './selection-strategies-types.js' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js' +import { + type IWorkerChoiceStrategy, + WorkerChoiceStrategies, + type WorkerChoiceStrategy, + type WorkerChoiceStrategyOptions, +} from './selection-strategies-types.js' /** * Selects the next worker in a round robin fashion. @@ -20,6 +22,10 @@ export class RoundRobinWorkerChoiceStrategy< > extends AbstractWorkerChoiceStrategy implements IWorkerChoiceStrategy { + /** @inheritDoc */ + public readonly name: WorkerChoiceStrategy = + WorkerChoiceStrategies.ROUND_ROBIN + /** @inheritDoc */ public constructor ( pool: IPool, diff --git a/src/pools/selection-strategies/selection-strategies-types.ts b/src/pools/selection-strategies/selection-strategies-types.ts index 393b70981..19a0e2215 100644 --- a/src/pools/selection-strategies/selection-strategies-types.ts +++ b/src/pools/selection-strategies/selection-strategies-types.ts @@ -71,6 +71,10 @@ export interface IWorkerChoiceStrategy { * @returns The worker node key or `undefined`. */ readonly choose: () => number | undefined + /** + * The worker choice strategy name. + */ + readonly name: WorkerChoiceStrategy /** * Removes the worker node key from strategy internals. * @param workerNodeKey - The worker node key. diff --git a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts index 769a5c02b..cf88d5106 100644 --- a/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts +++ b/src/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.ts @@ -1,13 +1,15 @@ import type { IPool } from '../pool.js' import type { IWorker } from '../worker.js' -import type { - IWorkerChoiceStrategy, - TaskStatisticsRequirements, - WorkerChoiceStrategyOptions, -} from './selection-strategies-types.js' import { DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS } from '../utils.js' import { AbstractWorkerChoiceStrategy } from './abstract-worker-choice-strategy.js' +import { + type IWorkerChoiceStrategy, + type TaskStatisticsRequirements, + WorkerChoiceStrategies, + type WorkerChoiceStrategy, + type WorkerChoiceStrategyOptions, +} from './selection-strategies-types.js' /** * Selects the next worker with a weighted round robin scheduling algorithm. @@ -23,6 +25,10 @@ export class WeightedRoundRobinWorkerChoiceStrategy< > extends AbstractWorkerChoiceStrategy implements IWorkerChoiceStrategy { + /** @inheritDoc */ + public readonly name: WorkerChoiceStrategy = + WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN + /** @inheritDoc */ public override readonly taskStatisticsRequirements: TaskStatisticsRequirements = Object.freeze({ diff --git a/src/pools/selection-strategies/worker-choice-strategies-context.ts b/src/pools/selection-strategies/worker-choice-strategies-context.ts index fae1e1304..846916837 100644 --- a/src/pools/selection-strategies/worker-choice-strategies-context.ts +++ b/src/pools/selection-strategies/worker-choice-strategies-context.ts @@ -248,7 +248,7 @@ export class WorkerChoiceStrategiesContext< } if (workerNodeKey == null) { throw new Error( - `Worker node key chosen is null or undefined after ${retriesCount.toString()} retries` + `Worker node key chosen by ${workerChoiceStrategy.name} is null or undefined after ${retriesCount.toString()} retries` ) } return workerNodeKey diff --git a/tests/pools/selection-strategies/selection-strategies.test.mjs b/tests/pools/selection-strategies/selection-strategies.test.mjs index 89d1e3af9..7869709d6 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.mjs +++ b/tests/pools/selection-strategies/selection-strategies.test.mjs @@ -95,6 +95,11 @@ describe('Selection strategies test suite', () => { './tests/worker-files/thread/testWorker.mjs', { workerChoiceStrategy } ) + expect( + pool.workerChoiceStrategiesContext.workerChoiceStrategies.get( + workerChoiceStrategy + ).name + ).toBe(workerChoiceStrategy) expect( pool.workerChoiceStrategiesContext.workerChoiceStrategies.get( workerChoiceStrategy diff --git a/tests/pools/selection-strategies/worker-choice-strategies-context.test.mjs b/tests/pools/selection-strategies/worker-choice-strategies-context.test.mjs index 0d6a77edb..8d4d4fee3 100644 --- a/tests/pools/selection-strategies/worker-choice-strategies-context.test.mjs +++ b/tests/pools/selection-strategies/worker-choice-strategies-context.test.mjs @@ -96,7 +96,7 @@ describe('Worker choice strategies context test suite', () => { ) expect(() => workerChoiceStrategiesContext.execute()).toThrow( new Error( - `Worker node key chosen is null or undefined after ${workerChoiceStrategiesContext.retries} retries` + `Worker node key chosen by ${workerChoiceStrategyUndefinedStub.name} is null or undefined after ${workerChoiceStrategiesContext.retries} retries` ) ) const workerChoiceStrategyNullStub = createStubInstance( @@ -111,7 +111,7 @@ describe('Worker choice strategies context test suite', () => { ) expect(() => workerChoiceStrategiesContext.execute()).toThrow( new Error( - `Worker node key chosen is null or undefined after ${workerChoiceStrategiesContext.retries} retries` + `Worker node key chosen by ${workerChoiceStrategyNullStub.name} is null or undefined after ${workerChoiceStrategiesContext.retries} retries` ) ) }) -- 2.43.0