X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fworker%2Fcluster-worker.test.mjs;h=2ad7911380c9844a12157e0c50f1232f9e991a27;hb=884743b122a66be45c94d83d9230e28a9ab43836;hp=9f4f8c06ea3b5720d0a92673384f7b40014f4a1e;hpb=31847469b406e46688d8aafb880e250706dd8aee;p=poolifier.git diff --git a/tests/worker/cluster-worker.test.mjs b/tests/worker/cluster-worker.test.mjs index 9f4f8c06..2ad79113 100644 --- a/tests/worker/cluster-worker.test.mjs +++ b/tests/worker/cluster-worker.test.mjs @@ -19,12 +19,12 @@ describe('Cluster worker test suite', () => { it('Verify that sync kill handler is called when worker is killed', () => { const worker = new ClusterWorker(() => {}, { - killHandler: stub().returns() + killHandler: stub().returns(), }) worker.isMain = false worker.getMainWorker = stub().returns({ id: 1, - send: stub().returns() + send: stub().returns(), }) worker.handleKillMessage() expect(worker.getMainWorker.calledTwice).toBe(true) @@ -42,19 +42,25 @@ describe('Cluster worker test suite', () => { const worker = new ClusterWorker({ fn1, fn2 }) worker.getMainWorker = stub().returns({ id: 1, - send: stub().returns() + send: stub().returns(), }) expect(worker.removeTaskFunction(0, fn1)).toStrictEqual({ status: false, - error: new TypeError('name parameter is not a string') + error: new TypeError('name parameter is not a string'), }) expect(worker.removeTaskFunction('', fn1)).toStrictEqual({ status: false, - error: new TypeError('name parameter is an empty string') + error: new TypeError('name parameter is an empty string'), + }) + 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.get(DEFAULT_TASK_NAME)).toBeInstanceOf(Object) - expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Object) - expect(worker.taskFunctions.get('fn2')).toBeInstanceOf(Object) expect(worker.taskFunctions.size).toBe(3) expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual( worker.taskFunctions.get('fn1') @@ -63,17 +69,21 @@ describe('Cluster worker test suite', () => { status: false, error: new Error( 'Cannot remove the task function with the default reserved name' - ) + ), }) expect(worker.removeTaskFunction('fn1')).toStrictEqual({ status: false, error: new Error( 'Cannot remove the task function used as the default task function' - ) + ), }) 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) @@ -92,7 +102,7 @@ describe('Cluster worker test suite', () => { it('Verify that sendToMainWorker() method invokes the getMainWorker() and send() methods', () => { const worker = new ClusterWorker(() => {}) worker.getMainWorker = stub().returns({ - send: stub().returns() + send: stub().returns(), }) worker.sendToMainWorker({ ok: 1 }) expect(worker.getMainWorker.calledTwice).toBe(true)