() =>
new StubPoolWithIsMain(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
errorHandler: e => console.error(e)
}
it('Verify that pool statuses properties are set', async () => {
const pool = new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
expect(pool.starting).toBe(false)
expect(pool.started).toBe(true)
() =>
new FixedThreadPool(
undefined,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
).toThrowError(
new Error(
it('Verify that a non integer number of workers is checked', () => {
expect(
() =>
- new FixedThreadPool(0.25, './tests/worker-files/thread/testWorker.js')
+ new FixedThreadPool(0.25, './tests/worker-files/thread/testWorker.mjs')
).toThrowError(
new TypeError(
'Cannot instantiate a pool with a non safe integer number of workers'
new DynamicThreadPool(
0.5,
1,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
).toThrowError(
new TypeError(
)
expect(
() =>
- new DynamicThreadPool(2, 1, './tests/worker-files/thread/testWorker.js')
+ new DynamicThreadPool(
+ 2,
+ 1,
+ './tests/worker-files/thread/testWorker.mjs'
+ )
).toThrowError(
new RangeError(
'Cannot instantiate a dynamic pool with a maximum pool size inferior to the minimum pool size'
)
expect(
() =>
- new DynamicThreadPool(0, 0, './tests/worker-files/thread/testWorker.js')
+ new DynamicThreadPool(
+ 0,
+ 0,
+ './tests/worker-files/thread/testWorker.mjs'
+ )
).toThrowError(
new RangeError(
'Cannot instantiate a dynamic pool with a maximum pool size equal to zero'
it('Verify that pool options are checked', async () => {
let pool = new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
expect(pool.emitter).toBeInstanceOf(EventEmitterAsyncResource)
expect(pool.opts).toStrictEqual({
const testHandler = () => console.info('test handler executed')
pool = new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
workerChoiceStrategy: WorkerChoiceStrategies.LEAST_USED,
workerChoiceStrategyOptions: {
() =>
new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
workerChoiceStrategy: 'invalidStrategy'
}
() =>
new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
workerChoiceStrategyOptions: {
retries: 'invalidChoiceRetries'
() =>
new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
workerChoiceStrategyOptions: {
retries: -1
() =>
new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
workerChoiceStrategyOptions: { weights: {} }
}
() =>
new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
workerChoiceStrategyOptions: { measurement: 'invalidMeasurement' }
}
() =>
new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
enableTasksQueue: true,
tasksQueueOptions: 'invalidTasksQueueOptions'
() =>
new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
enableTasksQueue: true,
tasksQueueOptions: { concurrency: 0 }
() =>
new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
enableTasksQueue: true,
tasksQueueOptions: { concurrency: -1 }
() =>
new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
enableTasksQueue: true,
tasksQueueOptions: { concurrency: 0.2 }
() =>
new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
enableTasksQueue: true,
tasksQueueOptions: { size: 0 }
() =>
new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
enableTasksQueue: true,
tasksQueueOptions: { size: -1 }
() =>
new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
enableTasksQueue: true,
tasksQueueOptions: { size: 0.2 }
it('Verify that pool worker choice strategy options can be set', async () => {
const pool = new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
)
expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
it('Verify that pool tasks queue can be enabled/disabled', async () => {
const pool = new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
expect(pool.opts.enableTasksQueue).toBe(false)
expect(pool.opts.tasksQueueOptions).toBeUndefined()
it('Verify that pool tasks queue options can be set', async () => {
const pool = new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ enableTasksQueue: true }
)
expect(pool.opts.tasksQueueOptions).toStrictEqual({
it('Verify that pool info is set', async () => {
let pool = new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
expect(pool.info).toStrictEqual({
version,
pool = new DynamicThreadPool(
Math.floor(numberOfWorkers / 2),
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
for (const workerNode of pool.workerNodes) {
expect(workerNode).toBeInstanceOf(WorkerNode)
pool = new DynamicThreadPool(
Math.floor(numberOfWorkers / 2),
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
for (const workerNode of pool.workerNodes) {
expect(workerNode).toBeInstanceOf(WorkerNode)
const pool = new DynamicThreadPool(
Math.floor(numberOfWorkers / 2),
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
const promises = new Set()
const maxMultiplier = 2
it("Verify that pool event emitter 'busy' event can register a callback", async () => {
const pool = new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
expect(pool.emitter.eventNames()).toStrictEqual([])
const promises = new Set()
const pool = new DynamicThreadPool(
Math.floor(numberOfWorkers / 2),
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
expect(pool.emitter.eventNames()).toStrictEqual([])
const promises = new Set()
it("Verify that pool event emitter 'backPressure' event can register a callback", async () => {
const pool = new FixedThreadPool(
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
enableTasksQueue: true
}
const dynamicThreadPool = new DynamicThreadPool(
Math.floor(numberOfWorkers / 2),
numberOfWorkers,
- './tests/worker-files/thread/testMultipleTaskFunctionsWorker.js'
+ './tests/worker-files/thread/testMultipleTaskFunctionsWorker.mjs'
)
await waitPoolEvents(dynamicThreadPool, PoolEvents.ready, 1)
expect(dynamicThreadPool.hasTaskFunction(DEFAULT_TASK_NAME)).toBe(true)
const dynamicThreadPool = new DynamicThreadPool(
Math.floor(numberOfWorkers / 2),
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
await waitPoolEvents(dynamicThreadPool, PoolEvents.ready, 1)
await expect(
const dynamicThreadPool = new DynamicThreadPool(
Math.floor(numberOfWorkers / 2),
numberOfWorkers,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
await waitPoolEvents(dynamicThreadPool, PoolEvents.ready, 1)
expect(dynamicThreadPool.listTaskFunctionNames()).toStrictEqual([
const dynamicThreadPool = new DynamicThreadPool(
Math.floor(numberOfWorkers / 2),
numberOfWorkers,
- './tests/worker-files/thread/testMultipleTaskFunctionsWorker.js'
+ './tests/worker-files/thread/testMultipleTaskFunctionsWorker.mjs'
)
await waitPoolEvents(dynamicThreadPool, PoolEvents.ready, 1)
expect(dynamicThreadPool.listTaskFunctionNames()).toStrictEqual([
const dynamicThreadPool = new DynamicThreadPool(
Math.floor(numberOfWorkers / 2),
numberOfWorkers,
- './tests/worker-files/thread/testMultipleTaskFunctionsWorker.js'
+ './tests/worker-files/thread/testMultipleTaskFunctionsWorker.mjs'
)
await waitPoolEvents(dynamicThreadPool, PoolEvents.ready, 1)
await expect(
const pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
expect(pool.opts.workerChoiceStrategy).toBe(
WorkerChoiceStrategies.ROUND_ROBIN
for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) {
const pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(pool.opts.workerChoiceStrategy).toBe(workerChoiceStrategy)
const pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
pool.setWorkerChoiceStrategy(workerChoiceStrategy)
expect(pool.opts.workerChoiceStrategy).toBe(workerChoiceStrategy)
it('Verify available strategies default internals at pool creation', async () => {
const pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) {
expect(
const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(
const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN
const pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
// TODO: Create a better test to cover `RoundRobinWorkerChoiceStrategy#choose`
const pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
// TODO: Create a better test to cover `RoundRobinWorkerChoiceStrategy#choose`
await pool.destroy()
pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
results = new Set()
const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
)
expect(
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
)
expect(
const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_USED
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_USED
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(
it('Verify LEAST_USED strategy can be run in a fixed pool', async () => {
const pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy: WorkerChoiceStrategies.LEAST_USED }
)
// TODO: Create a better test to cover `LeastUsedWorkerChoiceStrategy#choose`
const pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy: WorkerChoiceStrategies.LEAST_USED }
)
// TODO: Create a better test to cover `LeastUsedWorkerChoiceStrategy#choose`
const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_BUSY
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_BUSY
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(
it('Verify LEAST_BUSY strategy can be run in a fixed pool', async () => {
const pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy: WorkerChoiceStrategies.LEAST_BUSY }
)
// TODO: Create a better test to cover `LeastBusyWorkerChoiceStrategy#choose`
const pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy: WorkerChoiceStrategies.LEAST_BUSY }
)
// TODO: Create a better test to cover `LeastBusyWorkerChoiceStrategy#choose`
const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_ELU
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_ELU
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(
it('Verify LEAST_ELU strategy can be run in a fixed pool', async () => {
const pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy: WorkerChoiceStrategies.LEAST_ELU }
)
// TODO: Create a better test to cover `LeastEluWorkerChoiceStrategy#choose`
const pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy: WorkerChoiceStrategies.LEAST_ELU }
)
// TODO: Create a better test to cover `LeastEluWorkerChoiceStrategy#choose`
const workerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
const workerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(
it('Verify FAIR_SHARE strategy can be run in a fixed pool', async () => {
const pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
)
// TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
const pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
)
// TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
const pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE,
workerChoiceStrategyOptions: {
const workerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
for (const workerNode of pool.workerNodes) {
workerNode.strategyData = {
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
for (const workerNode of pool.workerNodes) {
workerNode.strategyData = {
const workerChoiceStrategy = WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
const workerChoiceStrategy = WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(
it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a fixed pool', async () => {
const pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
)
// TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
const pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
)
// TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
const pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN,
workerChoiceStrategyOptions: {
const workerChoiceStrategy = WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
expect(
it('Verify INTERLEAVED_WEIGHTED_ROUND_ROBIN strategy can be run in a fixed pool', async () => {
const pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
workerChoiceStrategy:
WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN
const pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
workerChoiceStrategy:
WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN
WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
expect(
pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy: 'UNKNOWN_STRATEGY' }
)
).toThrowError("Invalid worker choice strategy 'UNKNOWN_STRATEGY'")
let pool
before(() => {
- pool = new FixedThreadPool(max, './tests/worker-files/thread/testWorker.js')
+ pool = new FixedThreadPool(
+ max,
+ './tests/worker-files/thread/testWorker.mjs'
+ )
})
afterEach(() => {
before(() => {
fixedPool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
dynamicPool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
})
const pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
errorHandler: e => console.error(e)
}
const pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
const res = await pool.execute()
expect(res).toStrictEqual({ ok: 1 })
const longRunningPool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/longRunningWorkerHardBehavior.js',
+ './tests/worker-files/thread/longRunningWorkerHardBehavior.mjs',
{
errorHandler: e => console.error(e),
onlineHandler: () => console.info('long executing worker is online'),
const longRunningPool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/longRunningWorkerSoftBehavior.js',
+ './tests/worker-files/thread/longRunningWorkerSoftBehavior.mjs',
{
errorHandler: e => console.error(e),
onlineHandler: () => console.info('long executing worker is online'),
const pool = new DynamicThreadPool(
0,
max,
- './tests/worker-files/thread/testWorker.js'
+ './tests/worker-files/thread/testWorker.mjs'
)
expect(pool).toBeInstanceOf(DynamicThreadPool)
// We need to clean up the resources after our test
const tasksConcurrency = 2
const pool = new FixedThreadPool(
numberOfThreads,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
errorHandler: e => console.error(e)
}
)
const queuePool = new FixedThreadPool(
numberOfThreads,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
enableTasksQueue: true,
tasksQueueOptions: {
)
const emptyPool = new FixedThreadPool(
numberOfThreads,
- './tests/worker-files/thread/emptyWorker.js',
+ './tests/worker-files/thread/emptyWorker.mjs',
{ exitHandler: () => console.info('empty pool worker exited') }
)
const echoPool = new FixedThreadPool(
numberOfThreads,
- './tests/worker-files/thread/echoWorker.js'
+ './tests/worker-files/thread/echoWorker.mjs'
)
const errorPool = new FixedThreadPool(
numberOfThreads,
- './tests/worker-files/thread/errorWorker.js',
+ './tests/worker-files/thread/errorWorker.mjs',
{
errorHandler: e => console.error(e)
}
)
const asyncErrorPool = new FixedThreadPool(
numberOfThreads,
- './tests/worker-files/thread/asyncErrorWorker.js',
+ './tests/worker-files/thread/asyncErrorWorker.mjs',
{
errorHandler: e => console.error(e)
}
)
const asyncPool = new FixedThreadPool(
numberOfThreads,
- './tests/worker-files/thread/asyncWorker.js'
+ './tests/worker-files/thread/asyncWorker.mjs'
)
after('Destroy all pools', async () => {
it("Verify that 'ready' event is emitted", async () => {
const pool = new FixedThreadPool(
numberOfThreads,
- './tests/worker-files/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.mjs',
{
errorHandler: e => console.error(e)
}
})
it('Verify that thread pool options are checked', async () => {
- const workerFilePath = './tests/worker-files/thread/testWorker.js'
+ const workerFilePath = './tests/worker-files/thread/testWorker.mjs'
let pool = new FixedThreadPool(numberOfThreads, workerFilePath)
expect(pool.opts.workerOptions).toBeUndefined()
await pool.destroy()
})
it('Should work even without opts in input', async () => {
- const workerFilePath = './tests/worker-files/thread/testWorker.js'
+ const workerFilePath = './tests/worker-files/thread/testWorker.mjs'
const pool = new FixedThreadPool(numberOfThreads, workerFilePath)
const res = await pool.execute()
expect(res).toStrictEqual({ ok: 1 })
})
it('Verify destroyWorkerNode()', async () => {
- const workerFilePath = './tests/worker-files/thread/testWorker.js'
+ const workerFilePath = './tests/worker-files/thread/testWorker.mjs'
const pool = new FixedThreadPool(numberOfThreads, workerFilePath)
const workerNodeKey = 0
let exitEvent = 0
it('Verify that a pool with zero worker fails', async () => {
expect(
- () => new FixedThreadPool(0, './tests/worker-files/thread/testWorker.js')
+ () => new FixedThreadPool(0, './tests/worker-files/thread/testWorker.mjs')
).toThrowError('Cannot instantiate a fixed pool with zero worker')
})
})
import { DEFAULT_TASK_NAME } from '../../lib/utils.js'
describe('Worker node test suite', () => {
- const threadWorker = new Worker('./tests/worker-files/thread/testWorker.js')
+ const threadWorker = new Worker('./tests/worker-files/thread/testWorker.mjs')
const clusterWorker = cluster.fork()
const threadWorkerNode = new WorkerNode(threadWorker, 12)
const clusterWorkerNode = new WorkerNode(clusterWorker, 12)
it('Verify getWorkerType() behavior', () => {
expect(
- getWorkerType(new Worker('./tests/worker-files/thread/testWorker.js'))
+ getWorkerType(new Worker('./tests/worker-files/thread/testWorker.mjs'))
).toBe(WorkerTypes.thread)
expect(getWorkerType(cluster.fork())).toBe(WorkerTypes.cluster)
})
it('Verify getWorkerId() behavior', () => {
- const threadWorker = new Worker('./tests/worker-files/thread/testWorker.js')
+ const threadWorker = new Worker(
+ './tests/worker-files/thread/testWorker.mjs'
+ )
const clusterWorker = cluster.fork()
expect(getWorkerId(threadWorker)).toBe(threadWorker.threadId)
expect(getWorkerId(clusterWorker)).toBe(clusterWorker.id)
-'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib')
-const { sleepTaskFunction } = require('../../test-utils')
+import { KillBehaviors, ThreadWorker } from '../../../lib/index.js'
+import { sleepTaskFunction } from '../../test-utils.js'
+/**
+ *
+ * @param data
+ */
async function error (data) {
return sleepTaskFunction(
data,
)
}
-module.exports = new ThreadWorker(error, {
+export default new ThreadWorker(error, {
killBehavior: KillBehaviors.HARD,
maxInactiveTime: 500
})
+++ /dev/null
-'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib')
-const { sleepTaskFunction } = require('../../test-utils')
-
-async function sleep (data) {
- return sleepTaskFunction(data, 2000)
-}
-
-module.exports = new ThreadWorker(sleep, {
- killBehavior: KillBehaviors.HARD,
- maxInactiveTime: 500
-})
--- /dev/null
+import { KillBehaviors, ThreadWorker } from '../../../lib/index.js'
+import { sleepTaskFunction } from '../../test-utils.js'
+
+/**
+ *
+ * @param data
+ */
+async function sleep (data) {
+ return sleepTaskFunction(data, 2000)
+}
+
+export default new ThreadWorker(sleep, {
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 500
+})
+++ /dev/null
-'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib')
-
-function echo (data) {
- return data
-}
-
-module.exports = new ThreadWorker(echo, {
- killBehavior: KillBehaviors.HARD
-})
--- /dev/null
+import { KillBehaviors, ThreadWorker } from '../../../lib/index.js'
+
+/**
+ *
+ * @param data
+ */
+function echo (data) {
+ return data
+}
+
+export default new ThreadWorker(echo, {
+ killBehavior: KillBehaviors.HARD
+})
+++ /dev/null
-'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib')
-
-function test () {}
-
-module.exports = new ThreadWorker(test, {
- killBehavior: KillBehaviors.HARD,
- maxInactiveTime: 500
-})
--- /dev/null
+import { KillBehaviors, ThreadWorker } from '../../../lib/index.js'
+
+/**
+ *
+ */
+function test () {}
+
+export default new ThreadWorker(test, {
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 500
+})
-'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib')
+import { KillBehaviors, ThreadWorker } from '../../../lib/index.js'
+/**
+ *
+ */
function error () {
throw new Error('Error Message from ThreadWorker')
}
-module.exports = new ThreadWorker(error, {
+export default new ThreadWorker(error, {
killBehavior: KillBehaviors.HARD,
maxInactiveTime: 500
})
+++ /dev/null
-'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib')
-const { sleepTaskFunction } = require('../../test-utils')
-
-async function sleep (data) {
- return sleepTaskFunction(data, 50000)
-}
-
-module.exports = new ThreadWorker(sleep, {
- killBehavior: KillBehaviors.HARD,
- maxInactiveTime: 500
-})
--- /dev/null
+import { KillBehaviors, ThreadWorker } from '../../../lib/index.js'
+import { sleepTaskFunction } from '../../test-utils.js'
+
+/**
+ *
+ * @param data
+ */
+async function sleep (data) {
+ return sleepTaskFunction(data, 50000)
+}
+
+export default new ThreadWorker(sleep, {
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 500
+})
+++ /dev/null
-'use strict'
-const { ThreadWorker } = require('../../../lib')
-const { sleepTaskFunction } = require('../../test-utils')
-
-async function sleep (data) {
- return sleepTaskFunction(data, 50000)
-}
-
-module.exports = new ThreadWorker(sleep, {
- maxInactiveTime: 500
-})
--- /dev/null
+import { ThreadWorker } from '../../../lib/index.js'
+import { sleepTaskFunction } from '../../test-utils.js'
+
+/**
+ *
+ * @param data
+ */
+async function sleep (data) {
+ return sleepTaskFunction(data, 50000)
+}
+
+export default new ThreadWorker(sleep, {
+ maxInactiveTime: 500
+})
-'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib')
-const {
- jsonIntegerSerialization,
+import { KillBehaviors, ThreadWorker } from '../../../lib/index.js'
+import {
factorial,
- fibonacci
-} = require('../../test-utils')
+ fibonacci,
+ jsonIntegerSerialization
+} from '../../test-utils.js'
-module.exports = new ThreadWorker(
+export default new ThreadWorker(
{
jsonIntegerSerialization: data => jsonIntegerSerialization(data.n),
factorial: data => factorial(data.n),
+++ /dev/null
-'use strict'
-const { ThreadWorker, KillBehaviors } = require('../../../lib')
-const { executeTaskFunction } = require('../../test-utils')
-const { TaskFunctions } = require('../../test-types')
-
-function test (data) {
- data = data || {}
- data.function = data.function || TaskFunctions.jsonIntegerSerialization
- return executeTaskFunction(data)
-}
-
-module.exports = new ThreadWorker(test, {
- killBehavior: KillBehaviors.HARD,
- maxInactiveTime: 500
-})
--- /dev/null
+import { KillBehaviors, ThreadWorker } from '../../../lib/index.js'
+import { executeTaskFunction } from '../../test-utils.js'
+import { TaskFunctions } from '../../test-types.js'
+
+/**
+ *
+ * @param data
+ */
+function test (data) {
+ data = data || {}
+ data.function = data.function || TaskFunctions.jsonIntegerSerialization
+ return executeTaskFunction(data)
+}
+
+export default new ThreadWorker(test, {
+ killBehavior: KillBehaviors.HARD,
+ maxInactiveTime: 500
+})