import { expect } from 'expect'
import { restore, stub } from 'sinon'
-import { CircularArray } from '../../lib/circular-array.cjs'
+import { CircularBuffer } from '../../lib/circular-buffer.cjs'
import {
DynamicClusterPool,
DynamicThreadPool,
WorkerTypes
} from '../../lib/index.cjs'
import { WorkerNode } from '../../lib/pools/worker-node.cjs'
-import { PriorityQueue } from '../../lib/priority-queue.cjs'
+import { defaultBucketSize, PriorityQueue } from '../../lib/priority-queue.cjs'
import { DEFAULT_TASK_NAME } from '../../lib/utils.cjs'
import { waitPoolEvents } from '../test-utils.cjs'
failed: 0
},
runTime: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer)
},
waitTime: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer)
},
elu: {
idle: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer)
},
active: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer)
}
}
})
expect(workerNode.tasksQueue).toBeInstanceOf(PriorityQueue)
expect(workerNode.tasksQueue.size).toBe(0)
expect(workerNode.tasksQueue.maxSize).toBe(0)
- expect(workerNode.tasksQueue.bucketSize).toBe(numberOfWorkers * 2)
+ expect(workerNode.tasksQueue.bucketSize).toBe(defaultBucketSize)
+ expect(workerNode.tasksQueue.enablePriority).toBe(false)
}
await pool.destroy()
pool = new DynamicThreadPool(
expect(workerNode.tasksQueue).toBeInstanceOf(PriorityQueue)
expect(workerNode.tasksQueue.size).toBe(0)
expect(workerNode.tasksQueue.maxSize).toBe(0)
- expect(workerNode.tasksQueue.bucketSize).toBe(numberOfWorkers * 2)
+ expect(workerNode.tasksQueue.bucketSize).toBe(defaultBucketSize)
+ expect(workerNode.tasksQueue.enablePriority).toBe(false)
}
await pool.destroy()
})
failed: 0
},
runTime: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
},
waitTime: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
},
elu: {
idle: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
},
active: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
}
}
})
failed: 0
},
runTime: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
},
waitTime: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
},
elu: {
idle: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
},
active: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
}
}
})
failed: 0
},
runTime: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
},
waitTime: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
},
elu: {
idle: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
},
active: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
}
}
})
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
numberOfWorkers * maxMultiplier
)
- expect(workerNode.usage.runTime.history.length).toBe(0)
- expect(workerNode.usage.waitTime.history.length).toBe(0)
- expect(workerNode.usage.elu.idle.history.length).toBe(0)
- expect(workerNode.usage.elu.active.history.length).toBe(0)
}
pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
for (const workerNode of pool.workerNodes) {
failed: 0
},
runTime: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
},
waitTime: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
},
elu: {
idle: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
},
active: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
}
}
})
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
numberOfWorkers * maxMultiplier
)
- expect(workerNode.usage.runTime.history.length).toBe(0)
- expect(workerNode.usage.waitTime.history.length).toBe(0)
- expect(workerNode.usage.elu.idle.history.length).toBe(0)
- expect(workerNode.usage.elu.active.history.length).toBe(0)
}
await pool.destroy()
})
failed: 0
},
runTime: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer)
},
waitTime: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer)
},
elu: expect.objectContaining({
idle: expect.objectContaining({
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
}),
active: expect.objectContaining({
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
})
})
})
{ name: 'fibonacci' }
])
expect(workerNode.taskFunctionsUsage.size).toBe(3)
+ expect(workerNode.usage.tasks.executed).toBeGreaterThan(0)
+ expect(workerNode.tasksQueue.enablePriority).toBe(false)
for (const taskFunctionProperties of pool.listTaskFunctionsProperties()) {
expect(
workerNode.getTaskFunctionWorkerUsage(taskFunctionProperties.name)
stolen: 0
},
runTime: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
},
waitTime: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
},
elu: {
idle: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
},
active: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
}
}
})
{ name: DEFAULT_TASK_NAME },
{ name: 'jsonIntegerSerialization' },
{ name: 'factorial' },
- { name: 'fibonacci' }
+ { name: 'fibonacci', priority: -5 }
])
expect(workerNode.taskFunctionsUsage.size).toBe(3)
expect(workerNode.usage.tasks.executed).toBeGreaterThan(0)
+ expect(workerNode.tasksQueue.enablePriority).toBe(true)
for (const taskFunctionProperties of pool.listTaskFunctionsProperties()) {
expect(
workerNode.getTaskFunctionWorkerUsage(taskFunctionProperties.name)
stolen: 0
},
runTime: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
},
waitTime: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
},
elu: {
idle: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
},
active: {
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer)
}
}
})