test: cleanups
authorJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 28 Apr 2024 19:09:49 +0000 (21:09 +0200)
committerJérôme Benoit <jerome.benoit@piment-noir.org>
Sun, 28 Apr 2024 19:09:49 +0000 (21:09 +0200)
Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
tests/pools/selection-strategies/selection-strategies-utils.test.mjs [moved from tests/pools/selection-strategies/strategies-utils.test.mjs with 100% similarity]
tests/pools/selection-strategies/worker-choice-strategies-context.test.mjs [moved from tests/pools/selection-strategies/worker-choice-strategy-context.test.mjs with 99% similarity]
tests/worker/abstract-worker.test.mjs
tests/worker/cluster-worker.test.mjs
tests/worker/thread-worker.test.mjs

similarity index 99%
rename from tests/pools/selection-strategies/worker-choice-strategy-context.test.mjs
rename to tests/pools/selection-strategies/worker-choice-strategies-context.test.mjs
index 83649cc7e2a53b932ef4d3fc7ad8ca4cdc194874..8fcd90b22eeb5a753a2affad79a500dec41cc98a 100644 (file)
@@ -15,7 +15,7 @@ import { RoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-str
 import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.cjs'
 import { WorkerChoiceStrategiesContext } from '../../../lib/pools/selection-strategies/worker-choice-strategies-context.cjs'
 
-describe('Worker choice strategy context test suite', () => {
+describe('Worker choice strategies context test suite', () => {
   const min = 1
   const max = 3
   let fixedPool, dynamicPool
index ee89911ce5b15bbe83075b94db38a3d1769fc370..d94cd4400d2cd70cb7f618c4b1af773700d8a6ec 100644 (file)
@@ -136,9 +136,13 @@ describe('Abstract worker test suite', () => {
   })
 
   it('Verify that taskFunctions parameter with unique function is taken', () => {
-    const worker = new ThreadWorker(() => {})
-    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toBeInstanceOf(Object)
-    expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Object)
+    const worker = new ThreadWorker(EMPTY_FUNCTION)
+    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn1')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
     expect(worker.taskFunctions.size).toBe(2)
     expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual(
       worker.taskFunctions.get('fn1')
@@ -195,9 +199,15 @@ describe('Abstract worker test suite', () => {
       return 2
     }
     const worker = new ClusterWorker({ fn1, fn2 })
-    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toBeInstanceOf(Object)
-    expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Object)
-    expect(worker.taskFunctions.get('fn2')).toBeInstanceOf(Object)
+    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn1')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn2')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
     expect(worker.taskFunctions.size).toBe(3)
     expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual(
       worker.taskFunctions.get('fn1')
@@ -296,8 +306,12 @@ describe('Abstract worker test suite', () => {
         "taskFunction object 'taskFunction' property 'undefined' is not a function"
       )
     })
-    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toBeInstanceOf(Object)
-    expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Object)
+    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn1')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
     expect(worker.taskFunctions.size).toBe(2)
     expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual(
       worker.taskFunctions.get('fn1')
@@ -309,17 +323,29 @@ describe('Abstract worker test suite', () => {
       )
     })
     worker.addTaskFunction('fn2', fn2)
-    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toBeInstanceOf(Object)
-    expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Object)
-    expect(worker.taskFunctions.get('fn2')).toBeInstanceOf(Object)
+    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn1')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn2')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
     expect(worker.taskFunctions.size).toBe(3)
     expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual(
       worker.taskFunctions.get('fn1')
     )
     worker.addTaskFunction('fn1', fn1Replacement)
-    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toBeInstanceOf(Object)
-    expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Object)
-    expect(worker.taskFunctions.get('fn2')).toBeInstanceOf(Object)
+    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn1')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn2')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
     expect(worker.taskFunctions.size).toBe(3)
     expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual(
       worker.taskFunctions.get('fn1')
@@ -357,9 +383,15 @@ describe('Abstract worker test suite', () => {
       status: false,
       error: new TypeError('name parameter is an empty string')
     })
-    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toBeInstanceOf(Object)
-    expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Object)
-    expect(worker.taskFunctions.get('fn2')).toBeInstanceOf(Object)
+    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn1')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn2')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
     expect(worker.taskFunctions.size).toBe(3)
     expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual(
       worker.taskFunctions.get('fn1')
index 9f4f8c06ea3b5720d0a92673384f7b40014f4a1e..70d63639dab40d0a61622f73a8e5da18809c7ec7 100644 (file)
@@ -52,9 +52,15 @@ describe('Cluster worker test suite', () => {
       status: false,
       error: new TypeError('name parameter is an empty string')
     })
-    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toBeInstanceOf(Object)
-    expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Object)
-    expect(worker.taskFunctions.get('fn2')).toBeInstanceOf(Object)
+    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn1')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn2')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
     expect(worker.taskFunctions.size).toBe(3)
     expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual(
       worker.taskFunctions.get('fn1')
@@ -72,8 +78,12 @@ describe('Cluster worker test suite', () => {
       )
     })
     worker.removeTaskFunction('fn2')
-    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toBeInstanceOf(Object)
-    expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Object)
+    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn1')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
     expect(worker.taskFunctions.get('fn2')).toBeUndefined()
     expect(worker.taskFunctions.size).toBe(2)
     expect(worker.getMainWorker.calledTwice).toBe(true)
index e1eaeb06f26a37de159b7e7fecd6840b5a3483fc..3151b90a4a04d367e262f9f3cee8bf8569bc25c4 100644 (file)
@@ -53,9 +53,15 @@ describe('Thread worker test suite', () => {
       status: false,
       error: new TypeError('name parameter is an empty string')
     })
-    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toBeInstanceOf(Object)
-    expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Object)
-    expect(worker.taskFunctions.get('fn2')).toBeInstanceOf(Object)
+    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn1')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn2')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
     expect(worker.taskFunctions.size).toBe(3)
     expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual(
       worker.taskFunctions.get('fn1')
@@ -73,8 +79,12 @@ describe('Thread worker test suite', () => {
       )
     })
     worker.removeTaskFunction('fn2')
-    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toBeInstanceOf(Object)
-    expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Object)
+    expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
+    expect(worker.taskFunctions.get('fn1')).toStrictEqual({
+      taskFunction: expect.any(Function)
+    })
     expect(worker.taskFunctions.get('fn2')).toBeUndefined()
     expect(worker.taskFunctions.size).toBe(2)
     expect(worker.port.postMessage.calledOnce).toBe(true)