refactor: remove unneeded worker choice strategy storage in intermediate
[poolifier.git] / tests / pools / selection-strategies / worker-choice-strategy-context.test.mjs
index 6615b8c445f0b069b645577017f2725685a0bafa..85ec426359c3fdbc0e0830404fe02d56886d7d99 100644 (file)
@@ -41,14 +41,25 @@ describe('Worker choice strategy context test suite', () => {
   })
 
   it('Verify that constructor() initializes the context with all the available worker choice strategies', () => {
-    const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
-      fixedPool
+    let workerChoiceStrategyContext = new WorkerChoiceStrategyContext(fixedPool)
+    expect(workerChoiceStrategyContext.workerChoiceStrategies.size).toBe(
+      Object.keys(WorkerChoiceStrategies).length
     )
+    workerChoiceStrategyContext = new WorkerChoiceStrategyContext(dynamicPool)
     expect(workerChoiceStrategyContext.workerChoiceStrategies.size).toBe(
       Object.keys(WorkerChoiceStrategies).length
     )
   })
 
+  it('Verify that constructor() initializes the context with retries attribute properly set', () => {
+    let workerChoiceStrategyContext = new WorkerChoiceStrategyContext(fixedPool)
+    expect(workerChoiceStrategyContext.retries).toBe(fixedPool.info.maxSize * 2)
+    workerChoiceStrategyContext = new WorkerChoiceStrategyContext(dynamicPool)
+    expect(workerChoiceStrategyContext.retries).toBe(
+      dynamicPool.info.maxSize * 2
+    )
+  })
+
   it('Verify that execute() return the worker node key chosen by the strategy with fixed pool', () => {
     const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
       fixedPool
@@ -96,10 +107,7 @@ describe('Worker choice strategy context test suite', () => {
     )
     expect(() => workerChoiceStrategyContext.execute()).toThrow(
       new Error(
-        `Worker node key chosen is null or undefined after ${
-          fixedPool.info.maxSize +
-          Object.keys(workerChoiceStrategyContext.opts.weights).length
-        } retries`
+        `Worker node key chosen is null or undefined after ${workerChoiceStrategyContext.retries} retries`
       )
     )
     const workerChoiceStrategyNullStub = createStubInstance(
@@ -115,10 +123,7 @@ describe('Worker choice strategy context test suite', () => {
     )
     expect(() => workerChoiceStrategyContext.execute()).toThrow(
       new Error(
-        `Worker node key chosen is null or undefined after ${
-          fixedPool.info.maxSize +
-          Object.keys(workerChoiceStrategyContext.opts.weights).length
-        } retries`
+        `Worker node key chosen is null or undefined after ${workerChoiceStrategyContext.retries} retries`
       )
     )
   })