Bump typedoc from 0.20.30 to 0.20.31 (#272)
[poolifier.git] / tests / pools / abstract / abstract-pool.test.js
index 03a5db7eac5eef8ef5464907892bb27aecbb0442..bb6a2e4a89037e84bc99a3bccd14e675894a9a14 100644 (file)
@@ -1,5 +1,9 @@
 const expect = require('expect')
-const { FixedClusterPool, FixedThreadPool } = require('../../../lib/index')
+const {
+  FixedClusterPool,
+  FixedThreadPool,
+  WorkerChoiceStrategies
+} = require('../../../lib/index')
 const expectedError = new Error('Worker could not be found in tasks map')
 
 const numberOfWorkers = 1
@@ -56,11 +60,14 @@ describe('Abstract pool test suite', () => {
   })
 
   it('Verify that filePath is checked', () => {
+    const expectedError = new Error(
+      'Please specify a file with a worker implementation'
+    )
     expect(() => new FixedThreadPool(numberOfWorkers)).toThrowError(
-      new Error('Please specify a file with a worker implementation')
+      expectedError
     )
     expect(() => new FixedThreadPool(numberOfWorkers, '')).toThrowError(
-      new Error('Please specify a file with a worker implementation')
+      expectedError
     )
   })
 
@@ -97,18 +104,25 @@ describe('Abstract pool test suite', () => {
       numberOfWorkers,
       './tests/worker-files/thread/testWorker.js'
     )
-    expect(pool.opts.enableEvents).toEqual(true)
+    expect(pool.opts.enableEvents).toBe(true)
     expect(pool.emitter).toBeDefined()
+    expect(pool.opts.workerChoiceStrategy).toBe(
+      WorkerChoiceStrategies.ROUND_ROBIN
+    )
     pool.destroy()
     pool = new FixedThreadPool(
       numberOfWorkers,
       './tests/worker-files/thread/testWorker.js',
       {
+        workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED,
         enableEvents: false
       }
     )
-    expect(pool.opts.enableEvents).toEqual(false)
+    expect(pool.opts.enableEvents).toBe(false)
     expect(pool.emitter).toBeUndefined()
+    expect(pool.opts.workerChoiceStrategy).toBe(
+      WorkerChoiceStrategies.LESS_RECENTLY_USED
+    )
     pool.destroy()
   })
 
@@ -123,7 +137,7 @@ describe('Abstract pool test suite', () => {
     for (let i = 0; i < numberOfWorkers * 2; i++) {
       promises.push(pool.execute({ test: 'test' }))
     }
-    expect(poolBusy).toEqual(numberOfWorkers)
+    expect(poolBusy).toBe(numberOfWorkers)
     pool.destroy()
   })
 })