protected checkDynamicPoolSize (min: number, max: number): void {
if (this.type === PoolTypes.dynamic) {
- if (min > max) {
+ if (!Number.isSafeInteger(max)) {
+ throw new TypeError(
+ 'Cannot instantiate a dynamic pool with a non safe integer maximum pool size'
+ )
+ } else if (min > max) {
throw new RangeError(
'Cannot instantiate a dynamic pool with a maximum pool size inferior to the minimum pool size'
)
Response = unknown
> extends AbstractWorker<MessagePort, Data, Response> {
/**
- * Message port used to communicate with the main thread.
+ * Message port used to communicate with the main worker.
*/
private port!: MessagePort
/**
})
it('Verify that dynamic pool sizing is checked', () => {
+ expect(
+ () =>
+ new DynamicThreadPool(
+ 0.5,
+ 1,
+ './tests/worker-files/thread/testWorker.js'
+ )
+ ).toThrowError(
+ new TypeError(
+ 'Cannot instantiate a pool with a non safe integer number of workers'
+ )
+ )
+ expect(
+ () =>
+ new DynamicClusterPool(
+ 0,
+ 0.5,
+ './tests/worker-files/thread/testWorker.js'
+ )
+ ).toThrowError(
+ new TypeError(
+ 'Cannot instantiate a dynamic pool with a non safe integer maximum pool size'
+ )
+ )
expect(
() =>
new DynamicThreadPool(2, 1, './tests/worker-files/thread/testWorker.js')
)
expect(
() =>
- new DynamicThreadPool(1, 1, './tests/worker-files/thread/testWorker.js')
+ new DynamicClusterPool(
+ 1,
+ 1,
+ './tests/worker-files/thread/testWorker.js'
+ )
).toThrowError(
new RangeError(
'Cannot instantiate a dynamic pool with a minimum pool size equal to the maximum pool size. Use a fixed pool instead'