Refine attributes scope in dynamic pool code
authorJérôme Benoit <jerome.benoit@sap.com>
Fri, 21 Oct 2022 20:17:18 +0000 (22:17 +0200)
committerJérôme Benoit <jerome.benoit@sap.com>
Fri, 21 Oct 2022 20:17:18 +0000 (22:17 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@sap.com>
src/pools/cluster/dynamic.ts
src/pools/thread/dynamic.ts
tests/pools/abstract/abstract-pool.test.js

index 3c077876f8ac49cf44477f840b864e89e63b980a..a90e586039c6a2cc5f841618a0223aa0675983be 100644 (file)
@@ -27,7 +27,7 @@ export class DynamicClusterPool<
    */
   public constructor (
     min: number,
-    public readonly max: number,
+    protected readonly max: number,
     filePath: string,
     opts: ClusterPoolOptions = {}
   ) {
index 9ba218997195f09087145fed8ae7a0ce0edd0519..a6cc209a8bbd7c2b88732f986ccc066484f7b63d 100644 (file)
@@ -28,7 +28,7 @@ export class DynamicThreadPool<
    */
   public constructor (
     min: number,
-    public readonly max: number,
+    protected readonly max: number,
     filePath: string,
     opts: PoolOptions<ThreadWorkerWithMessageChannel> = {}
   ) {
index bc7bdd1eb7932a90257bcb730f1e78f6dab4de43..273de9a038f0a02eb0e4d554bd717107e06394f3 100644 (file)
@@ -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',
       {