From: Jérôme Benoit Date: Sun, 2 Jul 2023 11:00:10 +0000 (+0200) Subject: refactor: improve task error message X-Git-Tag: v2.6.7~16^2~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=eb7bf7441d410ca5d9ff9bb08f191ef22399371c;p=poolifier.git refactor: improve task error message Signed-off-by: Jérôme Benoit --- diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 889390a7..f71bf200 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -833,7 +833,7 @@ export abstract class AbstractPool< this.emitter.emit(PoolEvents.taskError, message.taskError) } promiseResponse.reject( - `${message.taskError.message} on worker '${message.taskError.workerId}` + `${message.taskError.message} on worker '${message.taskError.workerId}'` ) } else { promiseResponse.resolve(message.data as Response) diff --git a/src/pools/pool.ts b/src/pools/pool.ts index 87f4a8fa..367b4529 100644 --- a/src/pools/pool.ts +++ b/src/pools/pool.ts @@ -96,7 +96,7 @@ export interface TasksQueueOptions { * * @defaultValue 1 */ - concurrency?: number + readonly concurrency?: number } /** diff --git a/src/pools/selection-strategies/selection-strategies-types.ts b/src/pools/selection-strategies/selection-strategies-types.ts index dc174814..9f68c22f 100644 --- a/src/pools/selection-strategies/selection-strategies-types.ts +++ b/src/pools/selection-strategies/selection-strategies-types.ts @@ -62,7 +62,7 @@ export interface MeasurementOptions { /** * Set measurement median. */ - median: boolean + readonly median: boolean } /** @@ -72,32 +72,32 @@ export interface WorkerChoiceStrategyOptions { /** * Measurement to use for worker choice strategy. */ - measurement?: Measurement + readonly measurement?: Measurement /** * Runtime options. * * @defaultValue \{ median: false \} */ - runTime?: MeasurementOptions + readonly runTime?: MeasurementOptions /** * Wait time options. * * @defaultValue \{ median: false \} */ - waitTime?: MeasurementOptions + readonly waitTime?: MeasurementOptions /** * Event loop utilization options. * * @defaultValue \{ median: false \} */ - elu?: MeasurementOptions + readonly elu?: MeasurementOptions /** * Worker weights to use for weighted round robin worker selection strategy. * Weight is the tasks maximum average or median runtime in milliseconds. * * @defaultValue Computed worker weights automatically given the CPU performance. */ - weights?: Record + readonly weights?: Record } /** @@ -129,15 +129,15 @@ export interface TaskStatisticsRequirements { /** * Tasks runtime requirements. */ - runTime: MeasurementStatisticsRequirements + readonly runTime: MeasurementStatisticsRequirements /** * Tasks wait time requirements. */ - waitTime: MeasurementStatisticsRequirements + readonly waitTime: MeasurementStatisticsRequirements /** * Tasks event loop utilization requirements. */ - elu: MeasurementStatisticsRequirements + readonly elu: MeasurementStatisticsRequirements } /** @@ -149,7 +149,7 @@ export interface StrategyPolicy { /** * Expects direct usage of dynamic worker. */ - useDynamicWorker: boolean + readonly useDynamicWorker: boolean } /** diff --git a/src/pools/worker.ts b/src/pools/worker.ts index 664b6a76..379d350b 100644 --- a/src/pools/worker.ts +++ b/src/pools/worker.ts @@ -76,7 +76,7 @@ export interface MeasurementStatistics { /** * Measurement history. */ - history: CircularArray + readonly history: CircularArray } /** @@ -85,8 +85,8 @@ export interface MeasurementStatistics { * @internal */ export interface EventLoopUtilizationMeasurementStatistics { - idle: MeasurementStatistics - active: MeasurementStatistics + readonly idle: MeasurementStatistics + readonly active: MeasurementStatistics utilization: number } @@ -127,7 +127,7 @@ export interface WorkerInfo { /** * Worker id. */ - id: number | undefined + readonly id: number | undefined /** * Started flag. */ @@ -143,19 +143,19 @@ export interface WorkerUsage { /** * Tasks statistics. */ - tasks: TaskStatistics + readonly tasks: TaskStatistics /** * Tasks runtime statistics. */ - runTime: MeasurementStatistics + readonly runTime: MeasurementStatistics /** * Tasks wait time statistics. */ - waitTime: MeasurementStatistics + readonly waitTime: MeasurementStatistics /** * Tasks event loop utilization statistics. */ - elu: EventLoopUtilizationMeasurementStatistics + readonly elu: EventLoopUtilizationMeasurementStatistics } /** @@ -201,7 +201,7 @@ export interface WorkerNode { /** * Worker node worker info. */ - info: WorkerInfo + readonly info: WorkerInfo /** * Worker node worker usage statistics. */ diff --git a/src/utility-types.ts b/src/utility-types.ts index bca2de2b..a2f3de1c 100644 --- a/src/utility-types.ts +++ b/src/utility-types.ts @@ -11,15 +11,15 @@ export interface TaskError { /** * Worker id. */ - workerId: number + readonly workerId: number /** * Error message. */ - message: string + readonly message: string /** * Data passed to the worker triggering the error. */ - data?: Data + readonly data?: Data } /** @@ -29,15 +29,15 @@ export interface TaskPerformance { /** * Task performance timestamp. */ - timestamp: number + readonly timestamp: number /** * Task runtime. */ - runTime?: number + readonly runTime?: number /** * Task event loop utilization. */ - elu?: EventLoopUtilization + readonly elu?: EventLoopUtilization } /** diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index 631c59f0..60dac401 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -145,11 +145,8 @@ describe('Fixed cluster pool test suite', () => { } expect(inError).toBeDefined() expect(typeof inError === 'string').toBe(true) - expect(inError).toBe('Error Message from ClusterWorker') - expect(taskError).toStrictEqual({ - message: 'Error Message from ClusterWorker', - data - }) + expect(inError).toContain('Error Message from ClusterWorker on worker') + expect(taskError.data).toStrictEqual(data) expect( errorPool.workerNodes.some( workerNode => workerNode.usage.tasks.failed === 1 @@ -171,11 +168,10 @@ describe('Fixed cluster pool test suite', () => { } expect(inError).toBeDefined() expect(typeof inError === 'string').toBe(true) - expect(inError).toBe('Error Message from ClusterWorker:async') - expect(taskError).toStrictEqual({ - message: 'Error Message from ClusterWorker:async', - data - }) + expect(inError).toContain( + 'Error Message from ClusterWorker:async on worker' + ) + expect(taskError.data).toStrictEqual(data) expect( asyncErrorPool.workerNodes.some( workerNode => workerNode.usage.tasks.failed === 1 diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index 8a0cfead..f0448953 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -147,11 +147,10 @@ describe('Fixed thread pool test suite', () => { expect(inError).toBeInstanceOf(Error) expect(inError.message).toBeDefined() expect(typeof inError.message === 'string').toBe(true) - expect(inError.message).toBe('Error Message from ThreadWorker') - expect(taskError).toStrictEqual({ - message: new Error('Error Message from ThreadWorker'), - data - }) + expect(inError.message).toContain( + 'Error Message from ThreadWorker on worker' + ) + expect(taskError.data).toStrictEqual(data) expect( errorPool.workerNodes.some( workerNode => workerNode.usage.tasks.failed === 1 @@ -175,11 +174,10 @@ describe('Fixed thread pool test suite', () => { expect(inError).toBeInstanceOf(Error) expect(inError.message).toBeDefined() expect(typeof inError.message === 'string').toBe(true) - expect(inError.message).toBe('Error Message from ThreadWorker:async') - expect(taskError).toStrictEqual({ - message: new Error('Error Message from ThreadWorker:async'), - data - }) + expect(inError.message).toContain( + 'Error Message from ThreadWorker:async on worker' + ) + expect(taskError.data).toStrictEqual(data) expect( asyncErrorPool.workerNodes.some( workerNode => workerNode.usage.tasks.failed === 1