Refine attributes scope in dynamic pool code
[poolifier.git] / tests / pools / abstract / abstract-pool.test.js
index 0b33e36b85005dd843f8577d4bb0c6f34bee9c47..273de9a038f0a02eb0e4d554bd717107e06394f3 100644 (file)
@@ -1,6 +1,7 @@
 const { expect } = require('expect')
 const {
   FixedClusterPool,
+  DynamicThreadPool,
   FixedThreadPool,
   WorkerChoiceStrategies
 } = require('../../../lib/index')
@@ -8,14 +9,16 @@ const {
 describe('Abstract pool test suite', () => {
   const numberOfWorkers = 1
   const workerNotFoundInTasksUsageMapError = new Error(
-    'Worker could not be found in worker tasks usage map'
+    '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
     }
@@ -24,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',
           {
@@ -115,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'
     )
@@ -128,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',
       {
@@ -144,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',
       {
@@ -160,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',
       {
@@ -174,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',
       {
@@ -233,7 +236,8 @@ describe('Abstract pool test suite', () => {
   })
 
   it('Verify that worker pool tasks usage are reset at worker choice strategy change', async () => {
-    const pool = new FixedThreadPool(
+    const pool = new DynamicThreadPool(
+      numberOfWorkers,
       numberOfWorkers,
       './tests/worker-files/thread/testWorker.js'
     )