feat: add less busy worker choice strategy
[poolifier.git] / tests / pools / selection-strategies / worker-choice-strategy-context.test.js
index 0079e728295907bf76ca2c6cec5a25833372eac7..9380a038800abcb246c532240717940fe735e79f 100644 (file)
@@ -14,6 +14,9 @@ const {
 const {
   LessUsedWorkerChoiceStrategy
 } = require('../../../lib/pools/selection-strategies/less-used-worker-choice-strategy')
+const {
+  LessBusyWorkerChoiceStrategy
+} = require('../../../lib/pools/selection-strategies/less-busy-worker-choice-strategy')
 const {
   FairShareWorkerChoiceStrategy
 } = require('../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy')
@@ -140,6 +143,33 @@ describe('Worker choice strategy context test suite', () => {
     ).toBeInstanceOf(LessUsedWorkerChoiceStrategy)
   })
 
+  it('Verify that setWorkerChoiceStrategy() works with LESS_BUSY and fixed pool', () => {
+    const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
+      fixedPool
+    )
+    workerChoiceStrategyContext.setWorkerChoiceStrategy(
+      WorkerChoiceStrategies.LESS_BUSY
+    )
+    expect(
+      workerChoiceStrategyContext.getWorkerChoiceStrategy()
+    ).toBeInstanceOf(LessBusyWorkerChoiceStrategy)
+  })
+
+  it('Verify that setWorkerChoiceStrategy() works with LESS_BUSY and dynamic pool', () => {
+    const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
+      dynamicPool
+    )
+    workerChoiceStrategyContext.setWorkerChoiceStrategy(
+      WorkerChoiceStrategies.LESS_BUSY
+    )
+    expect(
+      workerChoiceStrategyContext.getWorkerChoiceStrategy()
+    ).toBeInstanceOf(DynamicPoolWorkerChoiceStrategy)
+    expect(
+      workerChoiceStrategyContext.getWorkerChoiceStrategy().workerChoiceStrategy
+    ).toBeInstanceOf(LessBusyWorkerChoiceStrategy)
+  })
+
   it('Verify that setWorkerChoiceStrategy() works with FAIR_SHARE and fixed pool', () => {
     const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
       fixedPool