From 915040cce0e378cc1e806391bf77af06880c12f2 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Sun, 28 Apr 2024 21:09:49 +0200 Subject: [PATCH] test: cleanups MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- ...js => selection-strategies-utils.test.mjs} | 0 ...worker-choice-strategies-context.test.mjs} | 2 +- tests/worker/abstract-worker.test.mjs | 66 ++++++++++++++----- tests/worker/cluster-worker.test.mjs | 20 ++++-- tests/worker/thread-worker.test.mjs | 20 ++++-- 5 files changed, 80 insertions(+), 28 deletions(-) rename tests/pools/selection-strategies/{strategies-utils.test.mjs => selection-strategies-utils.test.mjs} (100%) rename tests/pools/selection-strategies/{worker-choice-strategy-context.test.mjs => worker-choice-strategies-context.test.mjs} (99%) 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 83649cc7..8fcd90b2 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 ee89911c..d94cd440 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 9f4f8c06..70d63639 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 e1eaeb06..3151b90a 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) -- 2.34.1