X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fworker%2Fabstract-worker.test.mjs;h=575e065132b889ad4b96ba7f1440ab5db23b2759;hb=ae04560e0cdbf750bac433a691bfee1b0f5f54e1;hp=9058790b46654acbd2ea7ecc17ca0e38617dad3e;hpb=229e9e73566ed1960ba5be0534fb3aa2eeb115eb;p=poolifier.git diff --git a/tests/worker/abstract-worker.test.mjs b/tests/worker/abstract-worker.test.mjs index 9058790b..575e0651 100644 --- a/tests/worker/abstract-worker.test.mjs +++ b/tests/worker/abstract-worker.test.mjs @@ -60,9 +60,6 @@ describe('Abstract worker test suite', () => { expect(() => new ThreadWorker(() => {}, { killHandler: 0 })).toThrowError( new TypeError('killHandler option is not a function') ) - expect(() => new ThreadWorker(() => {}, { async: true })).toThrowError( - new TypeError('async option is deprecated') - ) }) it('Verify that worker options are set at worker creation', () => { @@ -176,39 +173,16 @@ describe('Abstract worker test suite', () => { ) }) - it('Verify that sync kill handler is called when worker is killed', () => { - const worker = new ClusterWorker(() => {}, { - killHandler: stub().returns() - }) - worker.isMain = false - worker.getMainWorker = stub().returns({ - id: 1, - send: stub().returns() - }) - worker.handleKillMessage() - expect(worker.getMainWorker().send.calledOnce).toBe(true) - expect(worker.opts.killHandler.calledOnce).toBe(true) - }) - it('Verify that async kill handler is called when worker is killed', () => { const killHandlerStub = stub().returns() const worker = new ClusterWorker(() => {}, { - killHandler: async () => Promise.resolve(killHandlerStub()) + killHandler: async () => await Promise.resolve(killHandlerStub()) }) worker.isMain = false worker.handleKillMessage() expect(killHandlerStub.calledOnce).toBe(true) }) - it('Verify that handleError() method is working properly', () => { - const error = new Error('Error as an error') - const worker = new ClusterWorker(() => {}) - expect(worker.handleError(error)).not.toBeInstanceOf(Error) - expect(worker.handleError(error)).toStrictEqual(error.message) - const errorMessage = 'Error as a string' - expect(worker.handleError(errorMessage)).toStrictEqual(errorMessage) - }) - it('Verify that getMainWorker() throw error if main worker is not set', () => { expect(() => new StubWorkerWithMainWorker(() => {}).getMainWorker() @@ -292,53 +266,6 @@ describe('Abstract worker test suite', () => { ) }) - it('Verify that removeTaskFunction() is working', () => { - const fn1 = () => { - return 1 - } - const fn2 = () => { - return 2 - } - const worker = new ClusterWorker({ fn1, fn2 }) - expect(worker.removeTaskFunction(0, fn1)).toStrictEqual({ - status: false, - 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') - }) - worker.getMainWorker = stub().returns({ - id: 1, - send: stub().returns() - }) - expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toBeInstanceOf(Function) - expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Function) - expect(worker.taskFunctions.get('fn2')).toBeInstanceOf(Function) - expect(worker.taskFunctions.size).toBe(3) - expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toStrictEqual( - worker.taskFunctions.get('fn1') - ) - expect(worker.removeTaskFunction(DEFAULT_TASK_NAME)).toStrictEqual({ - 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(Function) - expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Function) - expect(worker.taskFunctions.get('fn2')).toBeUndefined() - expect(worker.taskFunctions.size).toBe(2) - expect(worker.getMainWorker().send.calledOnce).toBe(true) - }) - it('Verify that listTaskFunctionNames() is working', () => { const fn1 = () => { return 1