X-Git-Url: https://git.piment-noir.org/?a=blobdiff_plain;f=tests%2Fpools%2Fabstract%2Fabstract-pool.test.js;h=5d6311b9b4b8b7d581531007803574d83935610b;hb=015cd3c7998314810359dcd1941466e09d6147f7;hp=9b32a7e09fb6d8d9ff9b90de389b9c41d3178ce1;hpb=0e2503fc5e7d8b5884682734074e7ec6ef0cd52f;p=poolifier.git diff --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index 9b32a7e0..5d6311b9 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -1,5 +1,5 @@ const expect = require('expect') -const { FixedThreadPool } = require('../../../lib/index') +const { FixedClusterPool, FixedThreadPool } = require('../../../lib/index') const expectedError = new Error('Worker could not be found in tasks map') class StubPoolWithTasksMapClear extends FixedThreadPool { @@ -18,10 +18,7 @@ describe('Abstract pool test suite', () => { it('Simulate worker not found during increaseWorkersTask', () => { const pool = new StubPoolWithTasksMapClear( 1, - './tests/worker-files/cluster/testWorker.js', - { - errorHandler: e => console.error(e) - } + './tests/worker-files/thread/testWorker.js' ) // Simulate worker not found. pool.removeAllWorker() @@ -31,7 +28,7 @@ describe('Abstract pool test suite', () => { it('Simulate worker not found during decreaseWorkersTasks', () => { const pool = new StubPoolWithTasksMapClear( 1, - './tests/worker-files/cluster/testWorker.js', + './tests/worker-files/thread/testWorker.js', { errorHandler: e => console.error(e) } @@ -42,23 +39,52 @@ describe('Abstract pool test suite', () => { }) it('Simulate pool creation from a non main thread/process', () => { - expect(() => { - const pool = new StubPoolWithIsMainMethod( - 1, - './tests/worker-files/cluster/testWorker.js', - { - errorHandler: e => console.error(e) - } - ) - }).toThrowError() + expect( + () => + new StubPoolWithIsMainMethod( + 1, + './tests/worker-files/thread/testWorker.js', + { + errorHandler: e => console.error(e) + } + ) + ).toThrowError(new Error('Cannot start a pool from a worker!')) }) it('Verify that filePath is checked', () => { - expect(() => { - const pool = new StubPoolWithIsMainMethod(1).toThrowError() - }) - expect(() => { - const pool = new StubPoolWithIsMainMethod(1, '').toThrowError() - }) + expect(() => new StubPoolWithIsMainMethod(1)).toThrowError( + new Error('Cannot start a pool from a worker!') + ) + expect(() => new StubPoolWithIsMainMethod(1, '')).toThrowError( + new Error('Cannot start a pool from a worker!') + ) + }) + + it('Verify that numberOfWorkers is checked', () => { + expect(() => new FixedThreadPool()).toThrowError( + new Error( + 'Cannot instantiate a pool without specifying the number of workers' + ) + ) + }) + + it('Verify that a negative number of workers is checked', () => { + expect( + () => + new FixedClusterPool(-1, './tests/worker-files/cluster/testWorker.js') + ).toThrowError( + new Error('Cannot instantiate a pool with a negative number of workers') + ) + }) + + it('Verify that a non integer number of workers is checked', () => { + expect( + () => + new FixedThreadPool(0.25, './tests/worker-files/thread/testWorker.js') + ).toThrowError( + new Error( + 'Cannot instantiate a pool with a non integer number of workers' + ) + ) }) })