Signed-off-by: Jérôme Benoit <jerome.benoit@piment-noir.org>
})
it('Verify that circular array size is valid at instance creation', () => {
})
it('Verify that circular array size is valid at instance creation', () => {
- expect(() => new CircularArray(0.25)).toThrowError(
+ expect(() => new CircularArray(0.25)).toThrow(
new TypeError('Invalid circular array size: 0.25 is not a safe integer')
)
new TypeError('Invalid circular array size: 0.25 is not a safe integer')
)
- expect(() => new CircularArray(-1)).toThrowError(
+ expect(() => new CircularArray(-1)).toThrow(
new RangeError('Invalid circular array size: -1 < 0')
)
new RangeError('Invalid circular array size: -1 < 0')
)
- expect(() => new CircularArray(Number.MAX_SAFE_INTEGER + 1)).toThrowError(
+ expect(() => new CircularArray(Number.MAX_SAFE_INTEGER + 1)).toThrow(
new TypeError(
`Invalid circular array size: ${
Number.MAX_SAFE_INTEGER + 1
new TypeError(
`Invalid circular array size: ${
Number.MAX_SAFE_INTEGER + 1
})
it('Verify that circular array resize works as intended', () => {
})
it('Verify that circular array resize works as intended', () => {
- expect(() => new CircularArray().resize(0.25)).toThrowError(
+ expect(() => new CircularArray().resize(0.25)).toThrow(
new TypeError('Invalid circular array size: 0.25 is not a safe integer')
)
new TypeError('Invalid circular array size: 0.25 is not a safe integer')
)
- expect(() => new CircularArray().resize(-1)).toThrowError(
+ expect(() => new CircularArray().resize(-1)).toThrow(
new RangeError('Invalid circular array size: -1 < 0')
)
expect(() =>
new CircularArray().resize(Number.MAX_SAFE_INTEGER + 1)
new RangeError('Invalid circular array size: -1 < 0')
)
expect(() =>
new CircularArray().resize(Number.MAX_SAFE_INTEGER + 1)
new TypeError(
`Invalid circular array size: ${
Number.MAX_SAFE_INTEGER + 1
new TypeError(
`Invalid circular array size: ${
Number.MAX_SAFE_INTEGER + 1
errorHandler: e => console.error(e)
}
)
errorHandler: e => console.error(e)
}
)
new Error(
'Cannot start a pool from a worker with the same type as the pool'
)
new Error(
'Cannot start a pool from a worker with the same type as the pool'
)
})
it('Verify that filePath is checked', () => {
})
it('Verify that filePath is checked', () => {
- expect(() => new FixedThreadPool(numberOfWorkers)).toThrowError(
+ expect(() => new FixedThreadPool(numberOfWorkers)).toThrow(
new Error("Cannot find the worker file 'undefined'")
)
expect(
() => new FixedThreadPool(numberOfWorkers, './dummyWorker.ts')
new Error("Cannot find the worker file 'undefined'")
)
expect(
() => new FixedThreadPool(numberOfWorkers, './dummyWorker.ts')
- ).toThrowError(new Error("Cannot find the worker file './dummyWorker.ts'"))
+ ).toThrow(new Error("Cannot find the worker file './dummyWorker.ts'"))
})
it('Verify that numberOfWorkers is checked', () => {
})
it('Verify that numberOfWorkers is checked', () => {
undefined,
'./tests/worker-files/thread/testWorker.mjs'
)
undefined,
'./tests/worker-files/thread/testWorker.mjs'
)
new Error(
'Cannot instantiate a pool without specifying the number of workers'
)
new Error(
'Cannot instantiate a pool without specifying the number of workers'
)
expect(
() =>
new FixedClusterPool(-1, './tests/worker-files/cluster/testWorker.js')
expect(
() =>
new FixedClusterPool(-1, './tests/worker-files/cluster/testWorker.js')
new RangeError(
'Cannot instantiate a pool with a negative number of workers'
)
new RangeError(
'Cannot instantiate a pool with a negative number of workers'
)
expect(
() =>
new FixedThreadPool(0.25, './tests/worker-files/thread/testWorker.mjs')
expect(
() =>
new FixedThreadPool(0.25, './tests/worker-files/thread/testWorker.mjs')
new TypeError(
'Cannot instantiate a pool with a non safe integer number of workers'
)
new TypeError(
'Cannot instantiate a pool with a non safe integer number of workers'
)
undefined,
'./tests/worker-files/cluster/testWorker.js'
)
undefined,
'./tests/worker-files/cluster/testWorker.js'
)
new TypeError(
'Cannot instantiate a dynamic pool without specifying the maximum pool size'
)
new TypeError(
'Cannot instantiate a dynamic pool without specifying the maximum pool size'
)
1,
'./tests/worker-files/thread/testWorker.mjs'
)
1,
'./tests/worker-files/thread/testWorker.mjs'
)
new TypeError(
'Cannot instantiate a pool with a non safe integer number of workers'
)
new TypeError(
'Cannot instantiate a pool with a non safe integer number of workers'
)
0.5,
'./tests/worker-files/cluster/testWorker.js'
)
0.5,
'./tests/worker-files/cluster/testWorker.js'
)
new TypeError(
'Cannot instantiate a dynamic pool with a non safe integer maximum pool size'
)
new TypeError(
'Cannot instantiate a dynamic pool with a non safe integer maximum pool size'
)
1,
'./tests/worker-files/thread/testWorker.mjs'
)
1,
'./tests/worker-files/thread/testWorker.mjs'
)
new RangeError(
'Cannot instantiate a dynamic pool with a maximum pool size inferior to the minimum pool size'
)
new RangeError(
'Cannot instantiate a dynamic pool with a maximum pool size inferior to the minimum pool size'
)
0,
'./tests/worker-files/thread/testWorker.mjs'
)
0,
'./tests/worker-files/thread/testWorker.mjs'
)
new RangeError(
'Cannot instantiate a dynamic pool with a maximum pool size equal to zero'
)
new RangeError(
'Cannot instantiate a dynamic pool with a maximum pool size equal to zero'
)
1,
'./tests/worker-files/cluster/testWorker.js'
)
1,
'./tests/worker-files/cluster/testWorker.js'
)
new RangeError(
'Cannot instantiate a dynamic pool with a minimum pool size equal to the maximum pool size. Use a fixed pool instead'
)
new RangeError(
'Cannot instantiate a dynamic pool with a minimum pool size equal to the maximum pool size. Use a fixed pool instead'
)
workerChoiceStrategy: 'invalidStrategy'
}
)
workerChoiceStrategy: 'invalidStrategy'
}
)
- ).toThrowError(
- new Error("Invalid worker choice strategy 'invalidStrategy'")
- )
+ ).toThrow(new Error("Invalid worker choice strategy 'invalidStrategy'"))
expect(
() =>
new FixedThreadPool(
expect(
() =>
new FixedThreadPool(
new TypeError(
'Invalid worker choice strategy options: retries must be an integer'
)
new TypeError(
'Invalid worker choice strategy options: retries must be an integer'
)
new RangeError(
"Invalid worker choice strategy options: retries '-1' must be greater or equal than zero"
)
new RangeError(
"Invalid worker choice strategy options: retries '-1' must be greater or equal than zero"
)
workerChoiceStrategyOptions: { weights: {} }
}
)
workerChoiceStrategyOptions: { weights: {} }
}
)
new Error(
'Invalid worker choice strategy options: must have a weight for each worker node'
)
new Error(
'Invalid worker choice strategy options: must have a weight for each worker node'
)
workerChoiceStrategyOptions: { measurement: 'invalidMeasurement' }
}
)
workerChoiceStrategyOptions: { measurement: 'invalidMeasurement' }
}
)
new Error(
"Invalid worker choice strategy options: invalid measurement 'invalidMeasurement'"
)
new Error(
"Invalid worker choice strategy options: invalid measurement 'invalidMeasurement'"
)
tasksQueueOptions: 'invalidTasksQueueOptions'
}
)
tasksQueueOptions: 'invalidTasksQueueOptions'
}
)
new TypeError('Invalid tasks queue options: must be a plain object')
)
expect(
new TypeError('Invalid tasks queue options: must be a plain object')
)
expect(
tasksQueueOptions: { concurrency: 0 }
}
)
tasksQueueOptions: { concurrency: 0 }
}
)
new RangeError(
'Invalid worker node tasks concurrency: 0 is a negative integer or zero'
)
new RangeError(
'Invalid worker node tasks concurrency: 0 is a negative integer or zero'
)
tasksQueueOptions: { concurrency: -1 }
}
)
tasksQueueOptions: { concurrency: -1 }
}
)
new RangeError(
'Invalid worker node tasks concurrency: -1 is a negative integer or zero'
)
new RangeError(
'Invalid worker node tasks concurrency: -1 is a negative integer or zero'
)
tasksQueueOptions: { concurrency: 0.2 }
}
)
tasksQueueOptions: { concurrency: 0.2 }
}
)
new TypeError('Invalid worker node tasks concurrency: must be an integer')
)
expect(
new TypeError('Invalid worker node tasks concurrency: must be an integer')
)
expect(
tasksQueueOptions: { size: 0 }
}
)
tasksQueueOptions: { size: 0 }
}
)
new RangeError(
'Invalid worker node tasks queue size: 0 is a negative integer or zero'
)
new RangeError(
'Invalid worker node tasks queue size: 0 is a negative integer or zero'
)
tasksQueueOptions: { size: -1 }
}
)
tasksQueueOptions: { size: -1 }
}
)
new RangeError(
'Invalid worker node tasks queue size: -1 is a negative integer or zero'
)
new RangeError(
'Invalid worker node tasks queue size: -1 is a negative integer or zero'
)
tasksQueueOptions: { size: 0.2 }
}
)
tasksQueueOptions: { size: 0.2 }
}
)
new TypeError('Invalid worker node tasks queue size: must be an integer')
)
})
new TypeError('Invalid worker node tasks queue size: must be an integer')
)
})
})
expect(() =>
pool.setWorkerChoiceStrategyOptions('invalidWorkerChoiceStrategyOptions')
})
expect(() =>
pool.setWorkerChoiceStrategyOptions('invalidWorkerChoiceStrategyOptions')
new TypeError(
'Invalid worker choice strategy options: must be a plain object'
)
new TypeError(
'Invalid worker choice strategy options: must be a plain object'
)
pool.setWorkerChoiceStrategyOptions({
retries: 'invalidChoiceRetries'
})
pool.setWorkerChoiceStrategyOptions({
retries: 'invalidChoiceRetries'
})
new TypeError(
'Invalid worker choice strategy options: retries must be an integer'
)
)
new TypeError(
'Invalid worker choice strategy options: retries must be an integer'
)
)
- expect(() =>
- pool.setWorkerChoiceStrategyOptions({ retries: -1 })
- ).toThrowError(
+ expect(() => pool.setWorkerChoiceStrategyOptions({ retries: -1 })).toThrow(
new RangeError(
"Invalid worker choice strategy options: retries '-1' must be greater or equal than zero"
)
)
new RangeError(
"Invalid worker choice strategy options: retries '-1' must be greater or equal than zero"
)
)
- expect(() =>
- pool.setWorkerChoiceStrategyOptions({ weights: {} })
- ).toThrowError(
+ expect(() => pool.setWorkerChoiceStrategyOptions({ weights: {} })).toThrow(
new Error(
'Invalid worker choice strategy options: must have a weight for each worker node'
)
)
expect(() =>
pool.setWorkerChoiceStrategyOptions({ measurement: 'invalidMeasurement' })
new Error(
'Invalid worker choice strategy options: must have a weight for each worker node'
)
)
expect(() =>
pool.setWorkerChoiceStrategyOptions({ measurement: 'invalidMeasurement' })
new Error(
"Invalid worker choice strategy options: invalid measurement 'invalidMeasurement'"
)
new Error(
"Invalid worker choice strategy options: invalid measurement 'invalidMeasurement'"
)
expect(workerNode.onEmptyQueue).toBeInstanceOf(Function)
expect(workerNode.onBackPressure).toBeInstanceOf(Function)
}
expect(workerNode.onEmptyQueue).toBeInstanceOf(Function)
expect(workerNode.onBackPressure).toBeInstanceOf(Function)
}
- expect(() =>
- pool.setTasksQueueOptions('invalidTasksQueueOptions')
- ).toThrowError(
+ expect(() => pool.setTasksQueueOptions('invalidTasksQueueOptions')).toThrow(
new TypeError('Invalid tasks queue options: must be a plain object')
)
new TypeError('Invalid tasks queue options: must be a plain object')
)
- expect(() => pool.setTasksQueueOptions({ concurrency: 0 })).toThrowError(
+ expect(() => pool.setTasksQueueOptions({ concurrency: 0 })).toThrow(
new RangeError(
'Invalid worker node tasks concurrency: 0 is a negative integer or zero'
)
)
new RangeError(
'Invalid worker node tasks concurrency: 0 is a negative integer or zero'
)
)
- expect(() => pool.setTasksQueueOptions({ concurrency: -1 })).toThrowError(
+ expect(() => pool.setTasksQueueOptions({ concurrency: -1 })).toThrow(
new RangeError(
'Invalid worker node tasks concurrency: -1 is a negative integer or zero'
)
)
new RangeError(
'Invalid worker node tasks concurrency: -1 is a negative integer or zero'
)
)
- expect(() => pool.setTasksQueueOptions({ concurrency: 0.2 })).toThrowError(
+ expect(() => pool.setTasksQueueOptions({ concurrency: 0.2 })).toThrow(
new TypeError('Invalid worker node tasks concurrency: must be an integer')
)
new TypeError('Invalid worker node tasks concurrency: must be an integer')
)
- expect(() => pool.setTasksQueueOptions({ size: 0 })).toThrowError(
+ expect(() => pool.setTasksQueueOptions({ size: 0 })).toThrow(
new RangeError(
'Invalid worker node tasks queue size: 0 is a negative integer or zero'
)
)
new RangeError(
'Invalid worker node tasks queue size: 0 is a negative integer or zero'
)
)
- expect(() => pool.setTasksQueueOptions({ size: -1 })).toThrowError(
+ expect(() => pool.setTasksQueueOptions({ size: -1 })).toThrow(
new RangeError(
'Invalid worker node tasks queue size: -1 is a negative integer or zero'
)
)
new RangeError(
'Invalid worker node tasks queue size: -1 is a negative integer or zero'
)
)
- expect(() => pool.setTasksQueueOptions({ size: 0.2 })).toThrowError(
+ expect(() => pool.setTasksQueueOptions({ size: 0.2 })).toThrow(
new TypeError('Invalid worker node tasks queue size: must be an integer')
)
await pool.destroy()
new TypeError('Invalid worker node tasks queue size: must be an integer')
)
await pool.destroy()
expect(pool.info.started).toBe(false)
expect(pool.info.ready).toBe(false)
expect(pool.workerNodes).toStrictEqual([])
expect(pool.info.started).toBe(false)
expect(pool.info.ready).toBe(false)
expect(pool.workerNodes).toStrictEqual([])
- await expect(pool.execute()).rejects.toThrowError(
+ await expect(pool.execute()).rejects.toThrow(
new Error('Cannot execute a task on not started pool')
)
pool.start()
new Error('Cannot execute a task on not started pool')
)
pool.start()
numberOfWorkers,
'./tests/worker-files/cluster/testWorker.js'
)
numberOfWorkers,
'./tests/worker-files/cluster/testWorker.js'
)
- await expect(pool.execute(undefined, 0)).rejects.toThrowError(
+ await expect(pool.execute(undefined, 0)).rejects.toThrow(
new TypeError('name argument must be a string')
)
new TypeError('name argument must be a string')
)
- await expect(pool.execute(undefined, '')).rejects.toThrowError(
+ await expect(pool.execute(undefined, '')).rejects.toThrow(
new TypeError('name argument must not be an empty string')
)
new TypeError('name argument must not be an empty string')
)
- await expect(pool.execute(undefined, undefined, {})).rejects.toThrowError(
+ await expect(pool.execute(undefined, undefined, {})).rejects.toThrow(
new TypeError('transferList argument must be an array')
)
await expect(pool.execute(undefined, 'unknown')).rejects.toBe(
"Task function 'unknown' not found"
)
await pool.destroy()
new TypeError('transferList argument must be an array')
)
await expect(pool.execute(undefined, 'unknown')).rejects.toBe(
"Task function 'unknown' not found"
)
await pool.destroy()
- await expect(pool.execute()).rejects.toThrowError(
+ await expect(pool.execute()).rejects.toThrow(
new Error('Cannot execute a task on not started pool')
)
})
new Error('Cannot execute a task on not started pool')
)
})
await waitPoolEvents(dynamicThreadPool, PoolEvents.ready, 1)
await expect(
dynamicThreadPool.addTaskFunction(0, () => {})
await waitPoolEvents(dynamicThreadPool, PoolEvents.ready, 1)
await expect(
dynamicThreadPool.addTaskFunction(0, () => {})
- ).rejects.toThrowError(new TypeError('name argument must be a string'))
+ ).rejects.toThrow(new TypeError('name argument must be a string'))
await expect(
dynamicThreadPool.addTaskFunction('', () => {})
await expect(
dynamicThreadPool.addTaskFunction('', () => {})
- ).rejects.toThrowError(
new TypeError('name argument must not be an empty string')
)
new TypeError('name argument must not be an empty string')
)
- await expect(
- dynamicThreadPool.addTaskFunction('test', 0)
- ).rejects.toThrowError(new TypeError('fn argument must be a function'))
- await expect(
- dynamicThreadPool.addTaskFunction('test', '')
- ).rejects.toThrowError(new TypeError('fn argument must be a function'))
+ await expect(dynamicThreadPool.addTaskFunction('test', 0)).rejects.toThrow(
+ new TypeError('fn argument must be a function')
+ )
+ await expect(dynamicThreadPool.addTaskFunction('test', '')).rejects.toThrow(
+ new TypeError('fn argument must be a function')
+ )
expect(dynamicThreadPool.listTaskFunctionNames()).toStrictEqual([
DEFAULT_TASK_NAME,
'test'
expect(dynamicThreadPool.listTaskFunctionNames()).toStrictEqual([
DEFAULT_TASK_NAME,
'test'
DEFAULT_TASK_NAME,
'test'
])
DEFAULT_TASK_NAME,
'test'
])
- await expect(
- dynamicThreadPool.removeTaskFunction('test')
- ).rejects.toThrowError(
+ await expect(dynamicThreadPool.removeTaskFunction('test')).rejects.toThrow(
new Error('Cannot remove a task function not handled on the pool side')
)
const echoTaskFunction = data => {
new Error('Cannot remove a task function not handled on the pool side')
)
const echoTaskFunction = data => {
'./tests/worker-files/thread/testMultipleTaskFunctionsWorker.mjs'
)
await waitPoolEvents(dynamicThreadPool, PoolEvents.ready, 1)
'./tests/worker-files/thread/testMultipleTaskFunctionsWorker.mjs'
)
await waitPoolEvents(dynamicThreadPool, PoolEvents.ready, 1)
- await expect(
- dynamicThreadPool.setDefaultTaskFunction(0)
- ).rejects.toThrowError(
+ await expect(dynamicThreadPool.setDefaultTaskFunction(0)).rejects.toThrow(
new Error(
"Task function operation 'default' failed on worker 31 with error: 'TypeError: name parameter is not a string'"
)
)
await expect(
dynamicThreadPool.setDefaultTaskFunction(DEFAULT_TASK_NAME)
new Error(
"Task function operation 'default' failed on worker 31 with error: 'TypeError: name parameter is not a string'"
)
)
await expect(
dynamicThreadPool.setDefaultTaskFunction(DEFAULT_TASK_NAME)
- ).rejects.toThrowError(
new Error(
"Task function operation 'default' failed on worker 31 with error: 'Error: Cannot set the default task function reserved name as the default task function'"
)
)
await expect(
dynamicThreadPool.setDefaultTaskFunction('unknown')
new Error(
"Task function operation 'default' failed on worker 31 with error: 'Error: Cannot set the default task function reserved name as the default task function'"
)
)
await expect(
dynamicThreadPool.setDefaultTaskFunction('unknown')
- ).rejects.toThrowError(
new Error(
"Task function operation 'default' failed on worker 31 with error: 'Error: Cannot set the default task function to a non-existing task function'"
)
new Error(
"Task function operation 'default' failed on worker 31 with error: 'Error: Cannot set the default task function to a non-existing task function'"
)
})
it('Validation of inputs test', () => {
})
it('Validation of inputs test', () => {
- expect(() => new DynamicClusterPool(min)).toThrowError(
+ expect(() => new DynamicClusterPool(min)).toThrow(
"Cannot find the worker file 'undefined'"
)
})
"Cannot find the worker file 'undefined'"
)
})
expect(
() =>
new FixedClusterPool(0, './tests/worker-files/cluster/testWorker.js')
expect(
() =>
new FixedClusterPool(0, './tests/worker-files/cluster/testWorker.js')
- ).toThrowError('Cannot instantiate a fixed pool with zero worker')
+ ).toThrow('Cannot instantiate a fixed pool with zero worker')
'./tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy: 'UNKNOWN_STRATEGY' }
)
'./tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy: 'UNKNOWN_STRATEGY' }
)
- ).toThrowError("Invalid worker choice strategy 'UNKNOWN_STRATEGY'")
+ ).toThrow("Invalid worker choice strategy 'UNKNOWN_STRATEGY'")
workerChoiceStrategyContext.workerChoiceStrategy,
workerChoiceStrategyUndefinedStub
)
workerChoiceStrategyContext.workerChoiceStrategy,
workerChoiceStrategyUndefinedStub
)
- expect(() => workerChoiceStrategyContext.execute()).toThrowError(
+ expect(() => workerChoiceStrategyContext.execute()).toThrow(
new Error('Worker node key chosen is null or undefined after 6 retries')
)
workerChoiceStrategyContext.workerChoiceStrategies.set(
workerChoiceStrategyContext.workerChoiceStrategy,
workerChoiceStrategyNullStub
)
new Error('Worker node key chosen is null or undefined after 6 retries')
)
workerChoiceStrategyContext.workerChoiceStrategies.set(
workerChoiceStrategyContext.workerChoiceStrategy,
workerChoiceStrategyNullStub
)
- expect(() => workerChoiceStrategyContext.execute()).toThrowError(
+ expect(() => workerChoiceStrategyContext.execute()).toThrow(
new Error('Worker node key chosen is null or undefined after 6 retries')
)
})
new Error('Worker node key chosen is null or undefined after 6 retries')
)
})
})
it('Validation of inputs test', () => {
})
it('Validation of inputs test', () => {
- expect(() => new DynamicThreadPool(min)).toThrowError(
+ expect(() => new DynamicThreadPool(min)).toThrow(
"Cannot find the worker file 'undefined'"
)
})
"Cannot find the worker file 'undefined'"
)
})
it('Verify that a pool with zero worker fails', () => {
expect(
() => new FixedThreadPool(0, './tests/worker-files/thread/testWorker.mjs')
it('Verify that a pool with zero worker fails', () => {
expect(
() => new FixedThreadPool(0, './tests/worker-files/thread/testWorker.mjs')
- ).toThrowError('Cannot instantiate a fixed pool with zero worker')
+ ).toThrow('Cannot instantiate a fixed pool with zero worker')
const clusterWorkerNode = new WorkerNode(clusterWorker, 12)
it('Worker node instantiation', () => {
const clusterWorkerNode = new WorkerNode(clusterWorker, 12)
it('Worker node instantiation', () => {
- expect(() => new WorkerNode()).toThrowError(
+ expect(() => new WorkerNode()).toThrow(
new TypeError('Cannot construct a worker node without a worker')
)
new TypeError('Cannot construct a worker node without a worker')
)
- expect(() => new WorkerNode(threadWorker)).toThrowError(
+ expect(() => new WorkerNode(threadWorker)).toThrow(
new TypeError(
'Cannot construct a worker node without a tasks queue back pressure size'
)
)
expect(
() => new WorkerNode(threadWorker, 'invalidTasksQueueBackPressureSize')
new TypeError(
'Cannot construct a worker node without a tasks queue back pressure size'
)
)
expect(
() => new WorkerNode(threadWorker, 'invalidTasksQueueBackPressureSize')
new TypeError(
'Cannot construct a worker node with a tasks queue back pressure size that is not an integer'
)
)
new TypeError(
'Cannot construct a worker node with a tasks queue back pressure size that is not an integer'
)
)
- expect(() => new WorkerNode(threadWorker, 0.2)).toThrowError(
+ expect(() => new WorkerNode(threadWorker, 0.2)).toThrow(
new TypeError(
'Cannot construct a worker node with a tasks queue back pressure size that is not an integer'
)
)
new TypeError(
'Cannot construct a worker node with a tasks queue back pressure size that is not an integer'
)
)
- expect(() => new WorkerNode(threadWorker, 0)).toThrowError(
+ expect(() => new WorkerNode(threadWorker, 0)).toThrow(
new RangeError(
'Cannot construct a worker node with a tasks queue back pressure size that is not a positive integer'
)
)
new RangeError(
'Cannot construct a worker node with a tasks queue back pressure size that is not a positive integer'
)
)
- expect(() => new WorkerNode(threadWorker, -1)).toThrowError(
+ expect(() => new WorkerNode(threadWorker, -1)).toThrow(
new RangeError(
'Cannot construct a worker node with a tasks queue back pressure size that is not a positive integer'
)
new RangeError(
'Cannot construct a worker node with a tasks queue back pressure size that is not a positive integer'
)
it('Worker node getTaskFunctionWorkerUsage()', () => {
expect(() =>
threadWorkerNode.getTaskFunctionWorkerUsage('invalidTaskFunction')
it('Worker node getTaskFunctionWorkerUsage()', () => {
expect(() =>
threadWorkerNode.getTaskFunctionWorkerUsage('invalidTaskFunction')
new TypeError(
"Cannot get task function worker usage for task function name 'invalidTaskFunction' when task function names list is not yet defined"
)
new TypeError(
"Cannot get task function worker usage for task function name 'invalidTaskFunction' when task function names list is not yet defined"
)
threadWorkerNode.info.taskFunctionNames = [DEFAULT_TASK_NAME, 'fn1']
expect(() =>
threadWorkerNode.getTaskFunctionWorkerUsage('invalidTaskFunction')
threadWorkerNode.info.taskFunctionNames = [DEFAULT_TASK_NAME, 'fn1']
expect(() =>
threadWorkerNode.getTaskFunctionWorkerUsage('invalidTaskFunction')
new TypeError(
"Cannot get task function worker usage for task function name 'invalidTaskFunction' when task function names list has less than 3 elements"
)
new TypeError(
"Cannot get task function worker usage for task function name 'invalidTaskFunction' when task function names list has less than 3 elements"
)
})
it('Verify that worker options are checked at worker creation', () => {
})
it('Verify that worker options are checked at worker creation', () => {
- expect(() => new ClusterWorker(() => {}, '')).toThrowError(
+ expect(() => new ClusterWorker(() => {}, '')).toThrow(
new TypeError('opts worker options parameter is not a plain object')
)
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(
+ expect(() => new ClusterWorker(() => {}, { killBehavior: '' })).toThrow(
+ new TypeError("killBehavior option '' is not valid")
+ )
+ expect(() => new ClusterWorker(() => {}, { killBehavior: 0 })).toThrow(
new TypeError("killBehavior option '0' is not valid")
)
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(
+ expect(() => new ThreadWorker(() => {}, { maxInactiveTime: '' })).toThrow(
+ new TypeError('maxInactiveTime option is not an integer')
+ )
+ expect(() => new ThreadWorker(() => {}, { maxInactiveTime: 0.5 })).toThrow(
+ new TypeError('maxInactiveTime option is not an integer')
+ )
+ expect(() => new ThreadWorker(() => {}, { maxInactiveTime: 0 })).toThrow(
new TypeError(
'maxInactiveTime option is not a positive integer greater or equal than 5'
)
)
new TypeError(
'maxInactiveTime option is not a positive integer greater or equal than 5'
)
)
- expect(
- () => new ThreadWorker(() => {}, { maxInactiveTime: 4 })
- ).toThrowError(
+ expect(() => new ThreadWorker(() => {}, { maxInactiveTime: 4 })).toThrow(
new TypeError(
'maxInactiveTime option is not a positive integer greater or equal than 5'
)
)
new TypeError(
'maxInactiveTime option is not a positive integer greater or equal than 5'
)
)
- expect(() => new ThreadWorker(() => {}, { killHandler: '' })).toThrowError(
+ expect(() => new ThreadWorker(() => {}, { killHandler: '' })).toThrow(
new TypeError('killHandler option is not a function')
)
new TypeError('killHandler option is not a function')
)
- expect(() => new ThreadWorker(() => {}, { killHandler: 0 })).toThrowError(
+ expect(() => new ThreadWorker(() => {}, { killHandler: 0 })).toThrow(
new TypeError('killHandler option is not a function')
)
})
new TypeError('killHandler option is not a function')
)
})
})
it('Verify that taskFunctions parameter is mandatory', () => {
})
it('Verify that taskFunctions parameter is mandatory', () => {
- expect(() => new ClusterWorker()).toThrowError(
+ expect(() => new ClusterWorker()).toThrow(
new Error('taskFunctions parameter is mandatory')
)
})
it('Verify that taskFunctions parameter is a function or a plain object', () => {
new Error('taskFunctions parameter is mandatory')
)
})
it('Verify that taskFunctions parameter is a function or a plain object', () => {
- expect(() => new ClusterWorker(0)).toThrowError(
+ expect(() => new ClusterWorker(0)).toThrow(
new TypeError(
'taskFunctions parameter is not a function or a plain object'
)
)
new TypeError(
'taskFunctions parameter is not a function or a plain object'
)
)
- expect(() => new ClusterWorker('')).toThrowError(
+ expect(() => new ClusterWorker('')).toThrow(
new TypeError(
'taskFunctions parameter is not a function or a plain object'
)
)
new TypeError(
'taskFunctions parameter is not a function or a plain object'
)
)
- expect(() => new ClusterWorker(true)).toThrowError(
+ expect(() => new ClusterWorker(true)).toThrow(
new TypeError(
'taskFunctions parameter is not a function or a plain object'
)
)
new TypeError(
'taskFunctions parameter is not a function or a plain object'
)
)
- expect(() => new ClusterWorker([])).toThrowError(
+ expect(() => new ClusterWorker([])).toThrow(
new TypeError(
'taskFunctions parameter is not a function or a plain object'
)
)
new TypeError(
'taskFunctions parameter is not a function or a plain object'
)
)
- expect(() => new ClusterWorker(new Map())).toThrowError(
+ expect(() => new ClusterWorker(new Map())).toThrow(
new TypeError(
'taskFunctions parameter is not a function or a plain object'
)
)
new TypeError(
'taskFunctions parameter is not a function or a plain object'
)
)
- expect(() => new ClusterWorker(new Set())).toThrowError(
+ expect(() => new ClusterWorker(new Set())).toThrow(
new TypeError(
'taskFunctions parameter is not a function or a plain object'
)
)
new TypeError(
'taskFunctions parameter is not a function or a plain object'
)
)
- expect(() => new ClusterWorker(new WeakMap())).toThrowError(
+ expect(() => new ClusterWorker(new WeakMap())).toThrow(
new TypeError(
'taskFunctions parameter is not a function or a plain object'
)
)
new TypeError(
'taskFunctions parameter is not a function or a plain object'
)
)
- expect(() => new ClusterWorker(new WeakSet())).toThrowError(
+ expect(() => new ClusterWorker(new WeakSet())).toThrow(
new TypeError(
'taskFunctions parameter is not a function or a plain object'
)
new TypeError(
'taskFunctions parameter is not a function or a plain object'
)
})
it('Verify that taskFunctions parameter is not an empty object', () => {
})
it('Verify that taskFunctions parameter is not an empty object', () => {
- expect(() => new ClusterWorker({})).toThrowError(
+ expect(() => new ClusterWorker({})).toThrow(
new Error('taskFunctions parameter object is empty')
)
})
new Error('taskFunctions parameter object is empty')
)
})
return 1
}
const fn2 = ''
return 1
}
const fn2 = ''
- expect(() => new ThreadWorker({ '': fn1 })).toThrowError(
+ expect(() => new ThreadWorker({ '': fn1 })).toThrow(
new TypeError('A taskFunctions parameter object key is an empty string')
)
new TypeError('A taskFunctions parameter object key is an empty string')
)
- expect(() => new ThreadWorker({ fn1, fn2 })).toThrowError(
+ expect(() => new ThreadWorker({ fn1, fn2 })).toThrow(
new TypeError('A taskFunctions parameter object value is not a function')
)
})
new TypeError('A taskFunctions parameter object value is not a function')
)
})
it('Verify that getMainWorker() throw error if main worker is not set', () => {
expect(() =>
new StubWorkerWithMainWorker(() => {}).getMainWorker()
it('Verify that getMainWorker() throw error if main worker is not set', () => {
expect(() =>
new StubWorkerWithMainWorker(() => {}).getMainWorker()
- ).toThrowError('Main worker not set')
+ ).toThrow('Main worker not set')
})
it('Verify that hasTaskFunction() is working', () => {
})
it('Verify that hasTaskFunction() is working', () => {