From: Jérôme Benoit Date: Mon, 10 Jul 2023 17:11:45 +0000 (+0200) Subject: fix: test for worker file existence X-Git-Tag: v2.6.15~14 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=3d6dd312a7825521cce506ebb7443bae36a111e6;p=poolifier.git fix: test for worker file existence Signed-off-by: Jérôme Benoit --- diff --git a/rollup.config.mjs b/rollup.config.mjs index 1410f161..d88f9734 100644 --- a/rollup.config.mjs +++ b/rollup.config.mjs @@ -48,6 +48,7 @@ export default { 'node:cluster', 'node:crypto', 'node:events', + 'node:fs', 'node:os', 'node:perf_hooks', 'node:worker_threads' diff --git a/src/pools/abstract-pool.ts b/src/pools/abstract-pool.ts index 27d8af0f..f1392edd 100644 --- a/src/pools/abstract-pool.ts +++ b/src/pools/abstract-pool.ts @@ -1,5 +1,6 @@ import { randomUUID } from 'node:crypto' import { performance } from 'node:perf_hooks' +import { existsSync } from 'node:fs' import type { MessageValue, PromiseResponseWrapper, @@ -137,10 +138,14 @@ export abstract class AbstractPool< private checkFilePath (filePath: string): void { if ( filePath == null || + typeof filePath !== 'string' || (typeof filePath === 'string' && filePath.trim().length === 0) ) { throw new Error('Please specify a file with a worker implementation') } + if (!existsSync(filePath)) { + throw new Error(`Cannot find the worker file '${filePath}'`) + } } private checkNumberOfWorkers (numberOfWorkers: number): void { 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 78960f10..907bd911 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 @@ -80,6 +80,7 @@ export class InterleavedWeightedRoundRobinWorkerChoiceStrategy< ) { const workerWeight = this.opts.weights?.[workerNodeKey] ?? this.defaultWorkerWeight + // if (this.isWorkerNodeReady(workerNodeKey) && workerWeight >= this.roundWeights[roundIndex]) { if (workerWeight >= this.roundWeights[roundIndex]) { roundId = roundIndex workerNodeId = workerNodeKey diff --git a/src/worker/abstract-worker.ts b/src/worker/abstract-worker.ts index 93a36bad..a6959a31 100644 --- a/src/worker/abstract-worker.ts +++ b/src/worker/abstract-worker.ts @@ -311,7 +311,6 @@ export abstract class AbstractWorker< this.checkAlive.bind(this), (this.opts.maxInactiveTime ?? DEFAULT_MAX_INACTIVE_TIME) / 2 ) - this.checkAlive.bind(this)() } /** diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 05e4c34e..c4fd6c65 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -5,8 +5,8 @@ const { FixedClusterPool, FixedThreadPool, PoolEvents, - WorkerChoiceStrategies, PoolTypes, + WorkerChoiceStrategies, WorkerTypes } = require('../../../lib') const { CircularArray } = require('../../../lib/circular-array') @@ -45,6 +45,15 @@ describe('Abstract pool test suite', () => { expect(() => new FixedThreadPool(numberOfWorkers, '')).toThrowError( expectedError ) + expect(() => new FixedThreadPool(numberOfWorkers, 0)).toThrowError( + expectedError + ) + expect(() => new FixedThreadPool(numberOfWorkers, true)).toThrowError( + expectedError + ) + expect( + () => new FixedThreadPool(numberOfWorkers, './dummyWorker.ts') + ).toThrowError(new Error("Cannot find the worker file './dummyWorker.ts'")) }) it('Verify that numberOfWorkers is checked', () => { diff --git a/tests/pools/selection-strategies/selection-strategies.test.js b/tests/pools/selection-strategies/selection-strategies.test.js index c3a01da6..6671b577 100644 --- a/tests/pools/selection-strategies/selection-strategies.test.js +++ b/tests/pools/selection-strategies/selection-strategies.test.js @@ -1,9 +1,9 @@ const { expect } = require('expect') const { - WorkerChoiceStrategies, DynamicThreadPool, + FixedClusterPool, FixedThreadPool, - FixedClusterPool + WorkerChoiceStrategies } = require('../../../lib') const { CircularArray } = require('../../../lib/circular-array')