From a8884ffdad6658f854f4048d768f7e56cf8d5032 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Fri, 21 Oct 2022 22:17:18 +0200 Subject: [PATCH] Refine attributes scope in dynamic pool code MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- src/pools/cluster/dynamic.ts | 2 +- src/pools/thread/dynamic.ts | 2 +- tests/pools/abstract/abstract-pool.test.js | 18 ++++++++++-------- 3 files changed, 12 insertions(+), 10 deletions(-) diff --git a/src/pools/cluster/dynamic.ts b/src/pools/cluster/dynamic.ts index 3c077876..a90e5860 100644 --- a/src/pools/cluster/dynamic.ts +++ b/src/pools/cluster/dynamic.ts @@ -27,7 +27,7 @@ export class DynamicClusterPool< */ public constructor ( min: number, - public readonly max: number, + protected readonly max: number, filePath: string, opts: ClusterPoolOptions = {} ) { diff --git a/src/pools/thread/dynamic.ts b/src/pools/thread/dynamic.ts index 9ba21899..a6cc209a 100644 --- a/src/pools/thread/dynamic.ts +++ b/src/pools/thread/dynamic.ts @@ -28,7 +28,7 @@ export class DynamicThreadPool< */ public constructor ( min: number, - public readonly max: number, + protected readonly max: number, filePath: string, opts: PoolOptions = {} ) { diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index bc7bdd1e..273de9a0 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -11,12 +11,14 @@ describe('Abstract pool test suite', () => { const workerNotFoundInTasksUsageMapError = new Error( 'Worker could not be found in workers tasks usage map' ) - class StubPoolWithWorkerTasksUsageMapClear extends FixedThreadPool { + class StubPoolWithRemoveAllWorker extends FixedThreadPool { removeAllWorker () { + this.workers = [] this.workersTasksUsage.clear() + this.promiseMap.clear() } } - class StubPoolWithIsMainMethod extends FixedThreadPool { + class StubPoolWithIsMain extends FixedThreadPool { isMain () { return false } @@ -25,7 +27,7 @@ describe('Abstract pool test suite', () => { it('Simulate pool creation from a non main thread/process', () => { expect( () => - new StubPoolWithIsMainMethod( + new StubPoolWithIsMain( numberOfWorkers, './tests/worker-files/thread/testWorker.js', { @@ -116,7 +118,7 @@ describe('Abstract pool test suite', () => { }) it('Simulate worker not found during increaseWorkerRunningTasks', async () => { - const pool = new StubPoolWithWorkerTasksUsageMapClear( + const pool = new StubPoolWithRemoveAllWorker( numberOfWorkers, './tests/worker-files/cluster/testWorker.js' ) @@ -129,7 +131,7 @@ describe('Abstract pool test suite', () => { }) it('Simulate worker not found during decreaseWorkerRunningTasks', async () => { - const pool = new StubPoolWithWorkerTasksUsageMapClear( + const pool = new StubPoolWithRemoveAllWorker( numberOfWorkers, './tests/worker-files/cluster/testWorker.js', { @@ -145,7 +147,7 @@ describe('Abstract pool test suite', () => { }) it('Simulate worker not found during stepWorkerRunTasks', async () => { - const pool = new StubPoolWithWorkerTasksUsageMapClear( + const pool = new StubPoolWithRemoveAllWorker( numberOfWorkers, './tests/worker-files/cluster/testWorker.js', { @@ -161,7 +163,7 @@ describe('Abstract pool test suite', () => { }) it('Simulate worker not found during updateWorkerTasksRunTime with strategy not requiring it', async () => { - const pool = new StubPoolWithWorkerTasksUsageMapClear( + const pool = new StubPoolWithRemoveAllWorker( numberOfWorkers, './tests/worker-files/cluster/testWorker.js', { @@ -175,7 +177,7 @@ describe('Abstract pool test suite', () => { }) it('Simulate worker not found during updateWorkerTasksRunTime with strategy requiring it', async () => { - const pool = new StubPoolWithWorkerTasksUsageMapClear( + const pool = new StubPoolWithRemoveAllWorker( numberOfWorkers, './tests/worker-files/cluster/testWorker.js', { -- 2.34.1