X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fworker%2Fabstract-worker.test.js;h=200b05acdff0f26a29c0eb4e2e760a64448935f5;hb=103057eedf4f7b18f009333806d0293bfb23e204;hp=161fed1886295162de3e99d319fe81640318610a;hpb=01bc762f43e8acaa2420246a4dfa0167c26d2e32;p=poolifier.git diff --git a/tests/worker/abstract-worker.test.js b/tests/worker/abstract-worker.test.js index 161fed18..200b05ac 100644 --- a/tests/worker/abstract-worker.test.js +++ b/tests/worker/abstract-worker.test.js @@ -24,6 +24,47 @@ describe('Abstract worker test suite', () => { }) }) + it('Verify that worker options are checked at worker creation', () => { + expect(() => new ClusterWorker(() => {}, '')).toThrowError( + new TypeError('opts worker options parameter is not a plain object') + ) + expect( + () => new ClusterWorker(() => {}, { killBehavior: '' }) + ).toThrowError(new TypeError("killBehavior option '' is not valid")) + expect(() => new ClusterWorker(() => {}, { killBehavior: 0 })).toThrowError( + new TypeError("killBehavior option '0' is not valid") + ) + expect( + () => new ThreadWorker(() => {}, { maxInactiveTime: '' }) + ).toThrowError(new TypeError('maxInactiveTime option is not an integer')) + expect( + () => new ThreadWorker(() => {}, { maxInactiveTime: 0.5 }) + ).toThrowError(new TypeError('maxInactiveTime option is not an integer')) + expect( + () => new ThreadWorker(() => {}, { maxInactiveTime: 0 }) + ).toThrowError( + new TypeError( + 'maxInactiveTime option is not a positive integer greater or equal than 5' + ) + ) + expect( + () => new ThreadWorker(() => {}, { maxInactiveTime: 4 }) + ).toThrowError( + new TypeError( + 'maxInactiveTime option is not a positive integer greater or equal than 5' + ) + ) + expect(() => new ThreadWorker(() => {}, { killHandler: '' })).toThrowError( + new TypeError('killHandler option is not a function') + ) + 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', () => { const killHandler = () => { console.info('Worker received kill message') @@ -31,8 +72,7 @@ describe('Abstract worker test suite', () => { const worker = new ClusterWorker(() => {}, { killBehavior: KillBehaviors.HARD, maxInactiveTime: 6000, - killHandler, - async: true + killHandler }) expect(worker.opts).toStrictEqual({ killBehavior: KillBehaviors.HARD, @@ -43,7 +83,7 @@ describe('Abstract worker test suite', () => { it('Verify that taskFunctions parameter is mandatory', () => { expect(() => new ClusterWorker()).toThrowError( - 'taskFunctions parameter is mandatory' + new Error('taskFunctions parameter is mandatory') ) }) @@ -160,7 +200,7 @@ describe('Abstract worker test suite', () => { expect(killHandlerStub.calledOnce).toBe(true) }) - it('Verify that handleError() method works properly', () => { + 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) @@ -175,7 +215,7 @@ describe('Abstract worker test suite', () => { ).toThrowError('Main worker not set') }) - it('Verify that hasTaskFunction() works', () => { + it('Verify that hasTaskFunction() is working', () => { const fn1 = () => { return 1 } @@ -199,7 +239,7 @@ describe('Abstract worker test suite', () => { expect(worker.hasTaskFunction('fn3')).toStrictEqual({ status: false }) }) - it('Verify that addTaskFunction() works', () => { + it('Verify that addTaskFunction() is working', () => { const fn1 = () => { return 1 } @@ -252,7 +292,7 @@ describe('Abstract worker test suite', () => { ) }) - it('Verify that removeTaskFunction() works', () => { + it('Verify that removeTaskFunction() is working', () => { const fn1 = () => { return 1 } @@ -299,7 +339,7 @@ describe('Abstract worker test suite', () => { expect(worker.getMainWorker().send.calledOnce).toBe(true) }) - it('Verify that listTaskFunctions() works', () => { + it('Verify that listTaskFunctionNames() is working', () => { const fn1 = () => { return 1 } @@ -314,7 +354,7 @@ describe('Abstract worker test suite', () => { ]) }) - it('Verify that setDefaultTaskFunction() works', () => { + it('Verify that setDefaultTaskFunction() is working', () => { const fn1 = () => { return 1 }