test: add more IWRR worker choice strategies testing
[poolifier.git] / tests / pools / selection-strategies / worker-choice-strategy-context.test.js
index fa380a5ae4320f0f4056bd48462e940992c60288..92b776f95f092387ee48851c0cbca6e51364ea6d 100644 (file)
@@ -12,17 +12,20 @@ const {
   RoundRobinWorkerChoiceStrategy
 } = require('../../../lib/pools/selection-strategies/round-robin-worker-choice-strategy')
 const {
-  LessUsedWorkerChoiceStrategy
-} = require('../../../lib/pools/selection-strategies/less-used-worker-choice-strategy')
+  LeastUsedWorkerChoiceStrategy
+} = require('../../../lib/pools/selection-strategies/least-used-worker-choice-strategy')
 const {
-  LessBusyWorkerChoiceStrategy
-} = require('../../../lib/pools/selection-strategies/less-busy-worker-choice-strategy')
+  LeastBusyWorkerChoiceStrategy
+} = require('../../../lib/pools/selection-strategies/least-busy-worker-choice-strategy')
 const {
   FairShareWorkerChoiceStrategy
 } = require('../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy')
 const {
   WeightedRoundRobinWorkerChoiceStrategy
 } = require('../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy')
+const {
+  InterleavedWeightedRoundRobinWorkerChoiceStrategy
+} = require('../../../lib/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy')
 
 describe('Worker choice strategy context test suite', () => {
   const min = 1
@@ -194,8 +197,8 @@ describe('Worker choice strategy context test suite', () => {
     )
   })
 
-  it('Verify that setWorkerChoiceStrategy() works with LESS_USED and fixed pool', () => {
-    const workerChoiceStrategy = WorkerChoiceStrategies.LESS_USED
+  it('Verify that setWorkerChoiceStrategy() works with LEAST_USED and fixed pool', () => {
+    const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_USED
     const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
       fixedPool
     )
@@ -204,14 +207,14 @@ describe('Worker choice strategy context test suite', () => {
       workerChoiceStrategyContext.workerChoiceStrategies.get(
         workerChoiceStrategy
       )
-    ).toBeInstanceOf(LessUsedWorkerChoiceStrategy)
+    ).toBeInstanceOf(LeastUsedWorkerChoiceStrategy)
     expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
       workerChoiceStrategy
     )
   })
 
-  it('Verify that setWorkerChoiceStrategy() works with LESS_USED and dynamic pool', () => {
-    const workerChoiceStrategy = WorkerChoiceStrategies.LESS_USED
+  it('Verify that setWorkerChoiceStrategy() works with LEAST_USED and dynamic pool', () => {
+    const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_USED
     const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
       dynamicPool
     )
@@ -220,14 +223,14 @@ describe('Worker choice strategy context test suite', () => {
       workerChoiceStrategyContext.workerChoiceStrategies.get(
         workerChoiceStrategy
       )
-    ).toBeInstanceOf(LessUsedWorkerChoiceStrategy)
+    ).toBeInstanceOf(LeastUsedWorkerChoiceStrategy)
     expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
       workerChoiceStrategy
     )
   })
 
-  it('Verify that setWorkerChoiceStrategy() works with LESS_BUSY and fixed pool', () => {
-    const workerChoiceStrategy = WorkerChoiceStrategies.LESS_BUSY
+  it('Verify that setWorkerChoiceStrategy() works with LEAST_BUSY and fixed pool', () => {
+    const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_BUSY
     const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
       fixedPool
     )
@@ -236,14 +239,14 @@ describe('Worker choice strategy context test suite', () => {
       workerChoiceStrategyContext.workerChoiceStrategies.get(
         workerChoiceStrategy
       )
-    ).toBeInstanceOf(LessBusyWorkerChoiceStrategy)
+    ).toBeInstanceOf(LeastBusyWorkerChoiceStrategy)
     expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
       workerChoiceStrategy
     )
   })
 
-  it('Verify that setWorkerChoiceStrategy() works with LESS_BUSY and dynamic pool', () => {
-    const workerChoiceStrategy = WorkerChoiceStrategies.LESS_BUSY
+  it('Verify that setWorkerChoiceStrategy() works with LEAST_BUSY and dynamic pool', () => {
+    const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_BUSY
     const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
       dynamicPool
     )
@@ -252,7 +255,7 @@ describe('Worker choice strategy context test suite', () => {
       workerChoiceStrategyContext.workerChoiceStrategies.get(
         workerChoiceStrategy
       )
-    ).toBeInstanceOf(LessBusyWorkerChoiceStrategy)
+    ).toBeInstanceOf(LeastBusyWorkerChoiceStrategy)
     expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
       workerChoiceStrategy
     )
@@ -322,6 +325,40 @@ describe('Worker choice strategy context test suite', () => {
     )
   })
 
+  it('Verify that setWorkerChoiceStrategy() works with INTERLEAVED_WEIGHTED_ROUND_ROBIN and fixed pool', () => {
+    const workerChoiceStrategy =
+      WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN
+    const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
+      fixedPool
+    )
+    workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy)
+    expect(
+      workerChoiceStrategyContext.workerChoiceStrategies.get(
+        workerChoiceStrategy
+      )
+    ).toBeInstanceOf(InterleavedWeightedRoundRobinWorkerChoiceStrategy)
+    expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
+      workerChoiceStrategy
+    )
+  })
+
+  it('Verify that setWorkerChoiceStrategy() works with INTERLEAVED_WEIGHTED_ROUND_ROBIN and dynamic pool', () => {
+    const workerChoiceStrategy =
+      WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN
+    const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
+      dynamicPool
+    )
+    workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy)
+    expect(
+      workerChoiceStrategyContext.workerChoiceStrategies.get(
+        workerChoiceStrategy
+      )
+    ).toBeInstanceOf(InterleavedWeightedRoundRobinWorkerChoiceStrategy)
+    expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
+      workerChoiceStrategy
+    )
+  })
+
   it('Verify that worker choice strategy options enable median runtime pool statistics', () => {
     const wwrWorkerChoiceStrategy = WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
     let workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
@@ -378,4 +415,61 @@ describe('Worker choice strategy context test suite', () => {
       true
     )
   })
+
+  it('Verify that worker choice strategy options enable median wait time pool statistics', () => {
+    const wwrWorkerChoiceStrategy = WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
+    let workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
+      fixedPool,
+      wwrWorkerChoiceStrategy,
+      {
+        medWaitTime: true
+      }
+    )
+    expect(
+      workerChoiceStrategyContext.getRequiredStatistics().avgWaitTime
+    ).toBe(false)
+    expect(
+      workerChoiceStrategyContext.getRequiredStatistics().medWaitTime
+    ).toBe(true)
+    workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
+      dynamicPool,
+      wwrWorkerChoiceStrategy,
+      {
+        medWaitTime: true
+      }
+    )
+    expect(
+      workerChoiceStrategyContext.getRequiredStatistics().avgWaitTime
+    ).toBe(false)
+    expect(
+      workerChoiceStrategyContext.getRequiredStatistics().medWaitTime
+    ).toBe(true)
+    const fsWorkerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE
+    workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
+      fixedPool,
+      fsWorkerChoiceStrategy,
+      {
+        medWaitTime: true
+      }
+    )
+    expect(
+      workerChoiceStrategyContext.getRequiredStatistics().avgWaitTime
+    ).toBe(false)
+    expect(
+      workerChoiceStrategyContext.getRequiredStatistics().medWaitTime
+    ).toBe(true)
+    workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
+      dynamicPool,
+      fsWorkerChoiceStrategy,
+      {
+        medWaitTime: true
+      }
+    )
+    expect(
+      workerChoiceStrategyContext.getRequiredStatistics().avgWaitTime
+    ).toBe(false)
+    expect(
+      workerChoiceStrategyContext.getRequiredStatistics().medWaitTime
+    ).toBe(true)
+  })
 })