WorkerTypes
} = require('../../../lib')
const { CircularArray } = require('../../../lib/circular-array')
-const { Queue } = require('../../../lib/queue')
+const { Deque } = require('../../../lib/deque')
const { version } = require('../../../package.json')
const { waitPoolEvents } = require('../../test-utils')
}
}
+ afterEach(() => {
+ sinon.restore()
+ })
+
it('Simulate pool creation from a non main thread/process', () => {
expect(
() =>
}
)
).toThrowError(
- '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 numberOfWorkers is checked', () => {
expect(() => new FixedThreadPool()).toThrowError(
- 'Cannot instantiate a pool without specifying the number of workers'
+ new Error(
+ 'Cannot instantiate a pool without specifying the number of workers'
+ )
)
})
expect(pool.opts.enableEvents).toBe(false)
expect(pool.opts.restartWorkerOnError).toBe(false)
expect(pool.opts.enableTasksQueue).toBe(true)
- expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 2 })
+ expect(pool.opts.tasksQueueOptions).toStrictEqual({
+ concurrency: 2,
+ size: 4
+ })
expect(pool.opts.workerChoiceStrategy).toBe(
WorkerChoiceStrategies.LEAST_USED
)
}
)
).toThrowError(
- new TypeError(
- 'Invalid worker tasks concurrency: 0 is a negative integer or zero'
+ new RangeError(
+ 'Invalid worker node tasks concurrency: 0 is a negative integer or zero'
)
)
expect(
}
)
).toThrowError(
- new TypeError('Invalid worker tasks concurrency: must be an integer')
+ new TypeError('Invalid worker node tasks concurrency: must be an integer')
)
})
expect(pool.opts.tasksQueueOptions).toBeUndefined()
pool.enableTasksQueue(true)
expect(pool.opts.enableTasksQueue).toBe(true)
- expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 1 })
+ expect(pool.opts.tasksQueueOptions).toStrictEqual({
+ concurrency: 1,
+ size: 4
+ })
pool.enableTasksQueue(true, { concurrency: 2 })
expect(pool.opts.enableTasksQueue).toBe(true)
- expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 2 })
+ expect(pool.opts.tasksQueueOptions).toStrictEqual({
+ concurrency: 2,
+ size: 4
+ })
pool.enableTasksQueue(false)
expect(pool.opts.enableTasksQueue).toBe(false)
expect(pool.opts.tasksQueueOptions).toBeUndefined()
'./tests/worker-files/thread/testWorker.js',
{ enableTasksQueue: true }
)
- expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 1 })
+ expect(pool.opts.tasksQueueOptions).toStrictEqual({
+ concurrency: 1,
+ size: 4
+ })
pool.setTasksQueueOptions({ concurrency: 2 })
- expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 2 })
+ expect(pool.opts.tasksQueueOptions).toStrictEqual({
+ concurrency: 2,
+ size: 4
+ })
expect(() =>
pool.setTasksQueueOptions('invalidTasksQueueOptions')
).toThrowError(
new TypeError('Invalid tasks queue options: must be a plain object')
)
expect(() => pool.setTasksQueueOptions({ concurrency: 0 })).toThrowError(
- new Error(
- 'Invalid worker 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(
- new Error(
- 'Invalid worker 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(
- new TypeError('Invalid worker tasks concurrency: must be an integer')
+ new TypeError('Invalid worker node tasks concurrency: must be an integer')
+ )
+ expect(() => pool.setTasksQueueOptions({ size: 0 })).toThrowError(
+ new RangeError(
+ 'Invalid worker node tasks queue max size: 0 is a negative integer or zero'
+ )
+ )
+ expect(() => pool.setTasksQueueOptions({ size: -1 })).toThrowError(
+ new RangeError(
+ 'Invalid worker node tasks queue max size: -1 is a negative integer or zero'
+ )
+ )
+ expect(() => pool.setTasksQueueOptions({ size: 0.2 })).toThrowError(
+ new TypeError(
+ 'Invalid worker node tasks queue max size: must be an integer'
+ )
)
await pool.destroy()
})
)
for (const workerNode of pool.workerNodes) {
expect(workerNode.tasksQueue).toBeDefined()
- expect(workerNode.tasksQueue).toBeInstanceOf(Queue)
+ expect(workerNode.tasksQueue).toBeInstanceOf(Deque)
expect(workerNode.tasksQueue.size).toBe(0)
expect(workerNode.tasksQueue.maxSize).toBe(0)
}
)
for (const workerNode of pool.workerNodes) {
expect(workerNode.tasksQueue).toBeDefined()
- expect(workerNode.tasksQueue).toBeInstanceOf(Queue)
+ expect(workerNode.tasksQueue).toBeInstanceOf(Deque)
expect(workerNode.tasksQueue.size).toBe(0)
expect(workerNode.tasksQueue.maxSize).toBe(0)
}