feat: add less busy worker choice strategy to internal benchmarks
[poolifier.git] / tests / pools / abstract / abstract-pool.test.js
index e6a7ad36cc5ae2ae5839fdd42497bbd86ce0cd9c..83290d6a0553243840e9c8b313d2ececacd4386d 100644 (file)
@@ -8,7 +8,7 @@ const {
 
 describe('Abstract pool test suite', () => {
   const numberOfWorkers = 1
-  const workerNotFoundInTasksUsageMapError = new Error(
+  const workerNotFoundInPoolError = new Error(
     'Worker could not be found in the pool'
   )
   class StubPoolWithRemoveAllWorker extends FixedThreadPool {
@@ -98,7 +98,7 @@ describe('Abstract pool test suite', () => {
       numberOfWorkers,
       './tests/worker-files/thread/testWorker.js',
       {
-        workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED,
+        workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED,
         enableEvents: false,
         messageHandler: testHandler,
         errorHandler: testHandler,
@@ -109,7 +109,7 @@ describe('Abstract pool test suite', () => {
     expect(pool.opts.enableEvents).toBe(false)
     expect(pool.emitter).toBeUndefined()
     expect(pool.opts.workerChoiceStrategy).toBe(
-      WorkerChoiceStrategies.LESS_RECENTLY_USED
+      WorkerChoiceStrategies.LESS_USED
     )
     expect(pool.opts.messageHandler).toStrictEqual(testHandler)
     expect(pool.opts.errorHandler).toStrictEqual(testHandler)
@@ -118,78 +118,18 @@ describe('Abstract pool test suite', () => {
     await pool.destroy()
   })
 
-  it('Simulate worker not found during increaseWorkerRunningTasks', async () => {
-    const pool = new StubPoolWithRemoveAllWorker(
-      numberOfWorkers,
-      './tests/worker-files/cluster/testWorker.js'
-    )
-    // Simulate worker not found.
-    pool.removeAllWorker()
-    expect(() => pool.increaseWorkerRunningTasks()).toThrowError(
-      workerNotFoundInTasksUsageMapError
-    )
-    await pool.destroy()
-  })
-
-  it('Simulate worker not found during decreaseWorkerRunningTasks', async () => {
-    const pool = new StubPoolWithRemoveAllWorker(
-      numberOfWorkers,
-      './tests/worker-files/cluster/testWorker.js',
-      {
-        errorHandler: e => console.error(e)
-      }
-    )
-    // Simulate worker not found.
-    pool.removeAllWorker()
-    expect(() => pool.decreaseWorkerRunningTasks()).toThrowError(
-      workerNotFoundInTasksUsageMapError
-    )
-    await pool.destroy()
-  })
-
-  it('Simulate worker not found during stepWorkerRunTasks', async () => {
-    const pool = new StubPoolWithRemoveAllWorker(
-      numberOfWorkers,
-      './tests/worker-files/cluster/testWorker.js',
-      {
-        errorHandler: e => console.error(e)
-      }
-    )
-    // Simulate worker not found.
-    pool.removeAllWorker()
-    expect(() => pool.stepWorkerRunTasks()).toThrowError(
-      workerNotFoundInTasksUsageMapError
-    )
-    await pool.destroy()
-  })
-
-  it('Simulate worker not found during updateWorkerTasksRunTime with strategy not requiring it', async () => {
-    const pool = new StubPoolWithRemoveAllWorker(
-      numberOfWorkers,
-      './tests/worker-files/cluster/testWorker.js',
-      {
-        errorHandler: e => console.error(e)
-      }
-    )
-    // Simulate worker not found.
-    pool.removeAllWorker()
-    expect(() => pool.updateWorkerTasksRunTime()).not.toThrowError()
-    await pool.destroy()
-  })
-
-  it('Simulate worker not found during updateWorkerTasksRunTime with strategy requiring it', async () => {
+  it('Simulate worker not found during getWorkerTasksUsage', async () => {
     const pool = new StubPoolWithRemoveAllWorker(
       numberOfWorkers,
       './tests/worker-files/cluster/testWorker.js',
       {
-        workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE,
         errorHandler: e => console.error(e)
       }
     )
     // Simulate worker not found.
     pool.removeAllWorker()
-    expect(() => pool.updateWorkerTasksRunTime()).toThrowError(
-      workerNotFoundInTasksUsageMapError
+    expect(() => pool.getWorkerTasksUsage()).toThrowError(
+      workerNotFoundInPoolError
     )
     await pool.destroy()
   })