1 const expect
= require('expect')
2 const { FixedThreadPool
} = require('../../../lib/index')
3 const expectedError
= new Error('Worker could not be found in tasks map')
5 class StubPoolWithTasksMapClear
extends FixedThreadPool
{
11 class StubPoolWithIsMainMethod
extends FixedThreadPool
{
17 describe('Abstract pool test suite ', () => {
18 it('Simulate worker not found during increaseWorkersTask', () => {
19 const pool
= new StubPoolWithTasksMapClear(
21 './tests/worker-files/cluster/testWorker.js',
23 errorHandler
: e
=> console
.error(e
)
26 // simulate worker not found.
27 pool
.removeAllWorker()
28 expect(() => pool
.increaseWorkersTask()).toThrowError(expectedError
)
31 it('Simulate worker not found during decreaseWorkersTasks', () => {
32 const pool
= new StubPoolWithTasksMapClear(
34 './tests/worker-files/cluster/testWorker.js',
36 errorHandler
: e
=> console
.error(e
)
39 // simulate worker not found.
40 pool
.removeAllWorker()
41 expect(() => pool
.decreaseWorkersTasks()).toThrowError(expectedError
)
44 it('Simulate pool creation from a non main thread/process', () => {
46 const pool
= new StubPoolWithIsMainMethod(
48 './tests/worker-files/cluster/testWorker.js',
50 errorHandler
: e
=> console
.error(e
)