1 const expect
= require('expect')
2 const { FixedClusterPool
, 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/thread/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/thread/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', () => {
47 new StubPoolWithIsMainMethod(
49 './tests/worker-files/thread/testWorker.js',
51 errorHandler
: e
=> console
.error(e
)
54 ).toThrowError(new Error('Cannot start a pool from a worker!'))
57 it('Verify that filePath is checked', () => {
58 expect(() => new StubPoolWithIsMainMethod(1)).toThrowError(
59 new Error('Cannot start a pool from a worker!')
61 expect(() => new StubPoolWithIsMainMethod(1, '')).toThrowError(
62 new Error('Cannot start a pool from a worker!')
66 it('Verify that numberOfWorkers is checked', () => {
67 expect(() => new FixedThreadPool()).toThrowError(
69 'Cannot instantiate a pool without specifying the number of workers'
74 it('Verify that a negative number of workers is checked', () => {
77 new FixedClusterPool(-1, './tests/worker-files/cluster/testWorker.js')
79 new Error('Cannot instantiate a pool with a negative number of workers')
83 it('Verify that a non integer number of workers is checked', () => {
86 new FixedThreadPool(0.25, './tests/worker-files/thread/testWorker.js')
89 'Cannot instantiate a pool with a non integer number of workers'