describe('Abstract pool test suite', () => {
const numberOfWorkers = 1
- const workerNotFoundInTasksUsageMapError = new Error(
+ const workerNotFoundInPoolError = new Error(
'Worker could not be found in the pool'
)
class StubPoolWithRemoveAllWorker extends FixedThreadPool {
numberOfWorkers,
'./tests/worker-files/thread/testWorker.js',
{
- workerChoiceStrategy: WorkerChoiceStrategies.LESS_RECENTLY_USED,
+ workerChoiceStrategy: WorkerChoiceStrategies.LESS_USED,
enableEvents: false,
messageHandler: testHandler,
errorHandler: testHandler,
expect(pool.opts.enableEvents).toBe(false)
expect(pool.emitter).toBeUndefined()
expect(pool.opts.workerChoiceStrategy).toBe(
- WorkerChoiceStrategies.LESS_RECENTLY_USED
+ WorkerChoiceStrategies.LESS_USED
)
expect(pool.opts.messageHandler).toStrictEqual(testHandler)
expect(pool.opts.errorHandler).toStrictEqual(testHandler)
await pool.destroy()
})
- it('Simulate worker not found during increaseWorkerRunningTasks', async () => {
- const pool = new StubPoolWithRemoveAllWorker(
- numberOfWorkers,
- './tests/worker-files/cluster/testWorker.js'
- )
- // Simulate worker not found.
- pool.removeAllWorker()
- expect(() => pool.increaseWorkerRunningTasks()).toThrowError(
- workerNotFoundInTasksUsageMapError
- )
- await pool.destroy()
- })
-
- it('Simulate worker not found during decreaseWorkerRunningTasks', async () => {
- const pool = new StubPoolWithRemoveAllWorker(
- numberOfWorkers,
- './tests/worker-files/cluster/testWorker.js',
- {
- errorHandler: e => console.error(e)
- }
- )
- // Simulate worker not found.
- pool.removeAllWorker()
- expect(() => pool.decreaseWorkerRunningTasks()).toThrowError(
- workerNotFoundInTasksUsageMapError
- )
- await pool.destroy()
- })
-
- it('Simulate worker not found during stepWorkerRunTasks', async () => {
- const pool = new StubPoolWithRemoveAllWorker(
- numberOfWorkers,
- './tests/worker-files/cluster/testWorker.js',
- {
- errorHandler: e => console.error(e)
- }
- )
- // Simulate worker not found.
- pool.removeAllWorker()
- expect(() => pool.stepWorkerRunTasks()).toThrowError(
- workerNotFoundInTasksUsageMapError
- )
- await pool.destroy()
- })
-
- it('Simulate worker not found during updateWorkerTasksRunTime with strategy not requiring it', async () => {
- const pool = new StubPoolWithRemoveAllWorker(
- numberOfWorkers,
- './tests/worker-files/cluster/testWorker.js',
- {
- errorHandler: e => console.error(e)
- }
- )
- // Simulate worker not found.
- pool.removeAllWorker()
- expect(() => pool.updateWorkerTasksRunTime()).not.toThrowError()
- await pool.destroy()
- })
-
- it('Simulate worker not found during updateWorkerTasksRunTime with strategy requiring it', async () => {
+ it('Simulate worker not found during getWorkerTasksUsage', async () => {
const pool = new StubPoolWithRemoveAllWorker(
numberOfWorkers,
'./tests/worker-files/cluster/testWorker.js',
{
- workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE,
errorHandler: e => console.error(e)
}
)
// Simulate worker not found.
pool.removeAllWorker()
- expect(() => pool.updateWorkerTasksRunTime()).toThrowError(
- workerNotFoundInTasksUsageMapError
+ expect(() => pool.getWorkerTasksUsage()).toThrowError(
+ workerNotFoundInPoolError
)
await pool.destroy()
})