From: Jérôme Benoit Date: Sun, 28 Apr 2024 19:09:49 +0000 (+0200) Subject: test: cleanups X-Git-Tag: v4.0.0~1^2~22 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=915040cce0e378cc1e806391bf77af06880c12f2;p=poolifier.git test: cleanups Signed-off-by: Jérôme Benoit --- diff --git a/tests/pools/selection-strategies/strategies-utils.test.mjs b/tests/pools/selection-strategies/selection-strategies-utils.test.mjs similarity index 100% rename from tests/pools/selection-strategies/strategies-utils.test.mjs rename to tests/pools/selection-strategies/selection-strategies-utils.test.mjs diff --git a/tests/pools/selection-strategies/worker-choice-strategy-context.test.mjs b/tests/pools/selection-strategies/worker-choice-strategies-context.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 83649cc7e..8fcd90b22 100644 --- a/tests/pools/selection-strategies/worker-choice-strategy-context.test.mjs +++ b/tests/pools/selection-strategies/worker-choice-strategies-context.test.mjs @@ -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 diff --git a/tests/worker/abstract-worker.test.mjs b/tests/worker/abstract-worker.test.mjs index ee89911ce..d94cd4400 100644 --- a/tests/worker/abstract-worker.test.mjs +++ b/tests/worker/abstract-worker.test.mjs @@ -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') diff --git a/tests/worker/cluster-worker.test.mjs b/tests/worker/cluster-worker.test.mjs index 9f4f8c06e..70d63639d 100644 --- a/tests/worker/cluster-worker.test.mjs +++ b/tests/worker/cluster-worker.test.mjs @@ -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) diff --git a/tests/worker/thread-worker.test.mjs b/tests/worker/thread-worker.test.mjs index e1eaeb06f..3151b90a4 100644 --- a/tests/worker/thread-worker.test.mjs +++ b/tests/worker/thread-worker.test.mjs @@ -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)