Allow worker choice strategy to specify their statistics requirements
[poolifier.git] / tests / pools / abstract / abstract-pool.test.js
index 24c7debd3c86deda03f4e312682d60546ed07c61..6a4da63d8a479b28410464bf9073118b28444fe4 100644 (file)
@@ -4,19 +4,15 @@ const {
   FixedThreadPool,
   WorkerChoiceStrategies
 } = require('../../../lib/index')
-
 const numberOfWorkers = 1
-
 const workerNotFoundInTasksUsageMapError = new Error(
   'Worker could not be found in worker tasks usage map'
 )
-
 class StubPoolWithWorkerTasksUsageMapClear extends FixedThreadPool {
   removeAllWorker () {
     this.workersTasksUsage.clear()
   }
 }
-
 class StubPoolWithIsMainMethod extends FixedThreadPool {
   isMain () {
     return false
@@ -162,11 +158,26 @@ describe('Abstract pool test suite', () => {
     pool.destroy()
   })
 
-  it('Simulate worker not found during updateWorkerTasksRunTime', () => {
+  it('Simulate worker not found during updateWorkerTasksRunTime with strategy not requiring it', () => {
+    const pool = new StubPoolWithWorkerTasksUsageMapClear(
+      numberOfWorkers,
+      './tests/worker-files/cluster/testWorker.js',
+      {
+        errorHandler: e => console.error(e)
+      }
+    )
+    // Simulate worker not found.
+    pool.removeAllWorker()
+    expect(() => pool.updateWorkerTasksRunTime()).not.toThrowError()
+    pool.destroy()
+  })
+
+  it('Simulate worker not found during updateWorkerTasksRunTime with strategy requiring it', () => {
     const pool = new StubPoolWithWorkerTasksUsageMapClear(
       numberOfWorkers,
       './tests/worker-files/cluster/testWorker.js',
       {
+        workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE,
         errorHandler: e => console.error(e)
       }
     )