+import { randomInt } from 'node:crypto'
+
import { expect } from 'expect'
+
+import { CircularBuffer } from '../../../lib/circular-buffer.cjs'
import {
DynamicClusterPool,
DynamicThreadPool,
FixedClusterPool,
FixedThreadPool,
- WorkerChoiceStrategies
-} from '../../../lib/index.js'
-import { CircularArray } from '../../../lib/circular-array.js'
+ WorkerChoiceStrategies,
+} from '../../../lib/index.cjs'
describe('Selection strategies test suite', () => {
const min = 0
expect(pool.opts.workerChoiceStrategy).toBe(
WorkerChoiceStrategies.ROUND_ROBIN
)
+ expect(pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy).toBe(
+ WorkerChoiceStrategies.ROUND_ROBIN
+ )
// We need to clean up the resources after our test
await pool.destroy()
})
{ workerChoiceStrategy }
)
expect(pool.opts.workerChoiceStrategy).toBe(workerChoiceStrategy)
- expect(pool.workerChoiceStrategyContext.workerChoiceStrategy).toBe(
- workerChoiceStrategy
- )
+ expect(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
+ ).toBe(workerChoiceStrategy)
await pool.destroy()
}
})
)
pool.setWorkerChoiceStrategy(workerChoiceStrategy)
expect(pool.opts.workerChoiceStrategy).toBe(workerChoiceStrategy)
- expect(pool.workerChoiceStrategyContext.workerChoiceStrategy).toBe(
- workerChoiceStrategy
- )
- expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
- retries: 6,
- runTime: { median: false },
- waitTime: { median: false },
- elu: { median: false }
- })
- expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({
- retries: 6,
- runTime: { median: false },
- waitTime: { median: false },
- elu: { median: false }
- })
+ expect(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
+ ).toBe(workerChoiceStrategy)
await pool.destroy()
}
for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) {
const pool = new DynamicClusterPool(
min,
max,
- './tests/worker-files/cluster/testWorker.js'
+ './tests/worker-files/cluster/testWorker.cjs'
)
- pool.setWorkerChoiceStrategy(workerChoiceStrategy, { retries: 3 })
+ pool.setWorkerChoiceStrategy(workerChoiceStrategy)
expect(pool.opts.workerChoiceStrategy).toBe(workerChoiceStrategy)
- expect(pool.workerChoiceStrategyContext.workerChoiceStrategy).toBe(
- workerChoiceStrategy
- )
- expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
- retries: 3,
- runTime: { median: false },
- waitTime: { median: false },
- elu: { median: false }
- })
- expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({
- retries: 3,
- runTime: { median: false },
- waitTime: { median: false },
- elu: { median: false }
- })
+ expect(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
+ ).toBe(workerChoiceStrategy)
await pool.destroy()
}
})
it('Verify available strategies default internals at pool creation', async () => {
- const pool = new FixedThreadPool(
- max,
- './tests/worker-files/thread/testWorker.mjs'
- )
for (const workerChoiceStrategy of Object.values(WorkerChoiceStrategies)) {
+ const pool = new FixedThreadPool(
+ max,
+ './tests/worker-files/thread/testWorker.mjs',
+ { workerChoiceStrategy }
+ )
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
workerChoiceStrategy
).nextWorkerNodeKey
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
workerChoiceStrategy
).previousWorkerNodeKey
).toBe(0)
workerChoiceStrategy === WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
) {
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
workerChoiceStrategy
- ).workerNodeVirtualTaskRunTime
+ ).workerNodeVirtualTaskExecutionTime
).toBe(0)
} else if (
workerChoiceStrategy ===
WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN
) {
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
workerChoiceStrategy
- ).workerNodeVirtualTaskRunTime
+ ).workerNodeVirtualTaskExecutionTime
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
workerChoiceStrategy
).roundId
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
workerChoiceStrategy
).workerNodeId
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
workerChoiceStrategy
- ).roundWeights
- ).toStrictEqual([
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).defaultWorkerWeight
- ])
+ ).roundWeights.length
+ ).toBe(1)
+ expect(
+ Number.isSafeInteger(
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).roundWeights[0]
+ )
+ ).toBe(true)
}
+ await pool.destroy()
}
- await pool.destroy()
})
it('Verify ROUND_ROBIN strategy default policy', async () => {
'./tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
+ expect(pool.workerChoiceStrategiesContext.getPolicy()).toStrictEqual({
dynamicWorkerUsage: false,
- dynamicWorkerReady: true
+ dynamicWorkerReady: true,
})
await pool.destroy()
pool = new DynamicThreadPool(
'./tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
+ expect(pool.workerChoiceStrategiesContext.getPolicy()).toStrictEqual({
dynamicWorkerUsage: false,
- dynamicWorkerReady: true
+ dynamicWorkerReady: true,
})
// We need to clean up the resources after our test
await pool.destroy()
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ pool.workerChoiceStrategiesContext.getTaskStatisticsRequirements()
).toStrictEqual({
runTime: {
aggregate: false,
average: false,
- median: false
+ median: false,
},
waitTime: {
aggregate: false,
average: false,
- median: false
+ median: false,
},
elu: {
aggregate: false,
average: false,
- median: false
- }
+ median: false,
+ },
})
await pool.destroy()
pool = new DynamicThreadPool(
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ pool.workerChoiceStrategiesContext.getTaskStatisticsRequirements()
).toStrictEqual({
runTime: {
aggregate: false,
average: false,
- median: false
+ median: false,
},
waitTime: {
aggregate: false,
average: false,
- median: false
+ median: false,
},
elu: {
aggregate: false,
average: false,
- median: false
- }
+ median: false,
+ },
})
// We need to clean up the resources after our test
await pool.destroy()
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ 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(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
).toBe(pool.workerNodes.length - 1)
// We need to clean up the resources after our test
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ 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.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
)
}
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
).toBe(pool.workerNodes.length - 1)
// We need to clean up the resources after our test
const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN
let pool = new FixedClusterPool(
max,
- './tests/worker-files/cluster/testWorker.js',
+ './tests/worker-files/cluster/testWorker.cjs',
{ workerChoiceStrategy }
)
let results = new Set()
await pool.destroy()
})
- it('Verify ROUND_ROBIN strategy internals are resets after setting it', async () => {
+ it("Verify ROUND_ROBIN strategy internals aren't reset after setting it", async () => {
const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN
let pool = new FixedThreadPool(
max,
'./tests/worker-files/thread/testWorker.mjs',
- { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
+ { workerChoiceStrategy }
)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).nextWorkerNodeKey
- ).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).previousWorkerNodeKey
- ).toBeDefined()
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
+ ).nextWorkerNodeKey = randomInt(1, max - 1)
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
+ ).previousWorkerNodeKey = randomInt(1, max - 1)
pool.setWorkerChoiceStrategy(workerChoiceStrategy)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
- ).toBe(0)
+ ).toBeGreaterThan(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
- ).toBe(0)
+ ).toBeGreaterThan(0)
await pool.destroy()
pool = new DynamicThreadPool(
min,
max,
'./tests/worker-files/thread/testWorker.mjs',
- { workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN }
+ { workerChoiceStrategy }
)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).nextWorkerNodeKey
- ).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).previousWorkerNodeKey
- ).toBeDefined()
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
+ ).nextWorkerNodeKey = randomInt(1, max - 1)
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
+ ).previousWorkerNodeKey = randomInt(1, max - 1)
pool.setWorkerChoiceStrategy(workerChoiceStrategy)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
- ).toBe(0)
+ ).toBeGreaterThan(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
- ).toBe(0)
+ ).toBeGreaterThan(0)
// We need to clean up the resources after our test
await pool.destroy()
})
'./tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
+ expect(pool.workerChoiceStrategiesContext.getPolicy()).toStrictEqual({
dynamicWorkerUsage: false,
- dynamicWorkerReady: true
+ dynamicWorkerReady: true,
})
await pool.destroy()
pool = new DynamicThreadPool(
'./tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
+ expect(pool.workerChoiceStrategiesContext.getPolicy()).toStrictEqual({
dynamicWorkerUsage: false,
- dynamicWorkerReady: true
+ dynamicWorkerReady: true,
})
// We need to clean up the resources after our test
await pool.destroy()
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ pool.workerChoiceStrategiesContext.getTaskStatisticsRequirements()
).toStrictEqual({
runTime: {
aggregate: false,
average: false,
- median: false
+ median: false,
},
waitTime: {
aggregate: false,
average: false,
- median: false
+ median: false,
},
elu: {
aggregate: false,
average: false,
- median: false
- }
+ median: false,
+ },
})
await pool.destroy()
pool = new DynamicThreadPool(
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ pool.workerChoiceStrategiesContext.getTaskStatisticsRequirements()
).toStrictEqual({
runTime: {
aggregate: false,
average: false,
- median: false
+ median: false,
},
waitTime: {
aggregate: false,
average: false,
- median: false
+ median: false,
},
elu: {
aggregate: false,
average: false,
- median: false
- }
+ median: false,
+ },
})
// We need to clean up the resources after our test
await pool.destroy()
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ 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.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
)
}
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
).toEqual(expect.any(Number))
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
).toEqual(expect.any(Number))
// We need to clean up the resources after our test
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ 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.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
)
}
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
).toEqual(expect.any(Number))
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
).toEqual(expect.any(Number))
// We need to clean up the resources after our test
'./tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
+ expect(pool.workerChoiceStrategiesContext.getPolicy()).toStrictEqual({
dynamicWorkerUsage: false,
- dynamicWorkerReady: true
+ dynamicWorkerReady: true,
})
await pool.destroy()
pool = new DynamicThreadPool(
'./tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
+ expect(pool.workerChoiceStrategiesContext.getPolicy()).toStrictEqual({
dynamicWorkerUsage: false,
- dynamicWorkerReady: true
+ dynamicWorkerReady: true,
})
// We need to clean up the resources after our test
await pool.destroy()
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ pool.workerChoiceStrategiesContext.getTaskStatisticsRequirements()
).toStrictEqual({
runTime: {
aggregate: true,
average: false,
- median: false
+ median: false,
},
waitTime: {
aggregate: true,
average: false,
- median: false
+ median: false,
},
elu: {
aggregate: false,
average: false,
- median: false
- }
+ median: false,
+ },
})
await pool.destroy()
pool = new DynamicThreadPool(
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ pool.workerChoiceStrategiesContext.getTaskStatisticsRequirements()
).toStrictEqual({
runTime: {
aggregate: true,
average: false,
- median: false
+ median: false,
},
waitTime: {
aggregate: true,
average: false,
- median: false
+ median: false,
},
elu: {
aggregate: false,
average: false,
- median: false
- }
+ median: false,
+ },
})
// We need to clean up the resources after our test
await pool.destroy()
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ failed: 0,
},
runTime: expect.objectContaining({
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer),
}),
waitTime: expect.objectContaining({
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer),
}),
elu: {
idle: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
active: {
- history: new CircularArray()
- }
- }
+ history: expect.any(CircularBuffer),
+ },
+ },
})
expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
}
}
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
).toEqual(expect.any(Number))
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
).toEqual(expect.any(Number))
// We need to clean up the resources after our test
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ failed: 0,
},
runTime: expect.objectContaining({
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer),
}),
waitTime: expect.objectContaining({
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer),
}),
elu: {
idle: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
active: {
- history: new CircularArray()
- }
- }
+ history: expect.any(CircularBuffer),
+ },
+ },
})
expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
}
}
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
).toEqual(expect.any(Number))
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
).toEqual(expect.any(Number))
// We need to clean up the resources after our test
'./tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
+ expect(pool.workerChoiceStrategiesContext.getPolicy()).toStrictEqual({
dynamicWorkerUsage: false,
- dynamicWorkerReady: true
+ dynamicWorkerReady: true,
})
await pool.destroy()
pool = new DynamicThreadPool(
'./tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
+ expect(pool.workerChoiceStrategiesContext.getPolicy()).toStrictEqual({
dynamicWorkerUsage: false,
- dynamicWorkerReady: true
+ dynamicWorkerReady: true,
})
// We need to clean up the resources after our test
await pool.destroy()
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ pool.workerChoiceStrategiesContext.getTaskStatisticsRequirements()
).toStrictEqual({
runTime: {
aggregate: false,
average: false,
- median: false
+ median: false,
},
waitTime: {
aggregate: false,
average: false,
- median: false
+ median: false,
},
elu: {
aggregate: true,
average: false,
- median: false
- }
+ median: false,
+ },
})
await pool.destroy()
pool = new DynamicThreadPool(
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ pool.workerChoiceStrategiesContext.getTaskStatisticsRequirements()
).toStrictEqual({
runTime: {
aggregate: false,
average: false,
- median: false
+ median: false,
},
waitTime: {
aggregate: false,
average: false,
- median: false
+ median: false,
},
elu: {
aggregate: true,
average: false,
- median: false
- }
+ median: false,
+ },
})
// We need to clean up the resources after our test
await pool.destroy()
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ 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),
+ }),
+ }),
})
expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
}
}
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
).toEqual(expect.any(Number))
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
).toEqual(expect.any(Number))
// We need to clean up the resources after our test
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ 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),
+ }),
+ }),
})
expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
}
}
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
).toEqual(expect.any(Number))
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
).toEqual(expect.any(Number))
// We need to clean up the resources after our test
'./tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
+ expect(pool.workerChoiceStrategiesContext.getPolicy()).toStrictEqual({
dynamicWorkerUsage: false,
- dynamicWorkerReady: true
+ dynamicWorkerReady: true,
})
await pool.destroy()
pool = new DynamicThreadPool(
'./tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
+ expect(pool.workerChoiceStrategiesContext.getPolicy()).toStrictEqual({
dynamicWorkerUsage: false,
- dynamicWorkerReady: true
+ dynamicWorkerReady: true,
})
// We need to clean up the resources after our test
await pool.destroy()
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ pool.workerChoiceStrategiesContext.getTaskStatisticsRequirements()
).toStrictEqual({
runTime: {
aggregate: true,
average: true,
- median: false
+ median: false,
},
waitTime: {
- aggregate: false,
- average: false,
- median: false
+ aggregate: true,
+ average: true,
+ median: false,
},
elu: {
aggregate: true,
average: true,
- median: false
- }
+ median: false,
+ },
})
await pool.destroy()
pool = new DynamicThreadPool(
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ pool.workerChoiceStrategiesContext.getTaskStatisticsRequirements()
).toStrictEqual({
runTime: {
aggregate: true,
average: true,
- median: false
+ median: false,
},
waitTime: {
- aggregate: false,
- average: false,
- median: false
+ aggregate: true,
+ average: true,
+ median: false,
},
elu: {
aggregate: true,
average: true,
- median: false
- }
+ median: false,
+ },
})
// We need to clean up the resources after our test
await pool.destroy()
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ failed: 0,
},
runTime: expect.objectContaining({
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer),
+ }),
+ waitTime: expect.objectContaining({
+ history: expect.any(CircularBuffer),
}),
- waitTime: {
- history: new CircularArray()
- },
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),
+ }),
+ }),
})
expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
} else {
expect(workerNode.usage.runTime.average).toBeGreaterThan(0)
}
+ if (workerNode.usage.waitTime.aggregate == null) {
+ expect(workerNode.usage.waitTime.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.waitTime.aggregate).toBeGreaterThan(0)
+ }
+ if (workerNode.usage.waitTime.average == null) {
+ expect(workerNode.usage.waitTime.average).toBeUndefined()
+ } else {
+ expect(workerNode.usage.waitTime.average).toBeGreaterThan(0)
+ }
if (workerNode.usage.elu.active.aggregate == null) {
expect(workerNode.usage.elu.active.aggregate).toBeUndefined()
} else {
expect(workerNode.strategyData.virtualTaskEndTimestamp).toBeGreaterThan(0)
}
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
).toEqual(expect.any(Number))
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
).toEqual(expect.any(Number))
// We need to clean up the resources after our test
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ failed: 0,
},
runTime: expect.objectContaining({
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer),
+ }),
+ waitTime: expect.objectContaining({
+ history: expect.any(CircularBuffer),
}),
- waitTime: {
- history: new CircularArray()
- },
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),
+ }),
+ }),
})
expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
} else {
expect(workerNode.usage.runTime.average).toBeGreaterThan(0)
}
+ if (workerNode.usage.waitTime.aggregate == null) {
+ expect(workerNode.usage.waitTime.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.waitTime.aggregate).toBeGreaterThan(0)
+ }
+ if (workerNode.usage.waitTime.average == null) {
+ expect(workerNode.usage.waitTime.average).toBeUndefined()
+ } else {
+ expect(workerNode.usage.waitTime.average).toBeGreaterThan(0)
+ }
if (workerNode.usage.elu.active.aggregate == null) {
expect(workerNode.usage.elu.active.aggregate).toBeUndefined()
} else {
expect(workerNode.strategyData.virtualTaskEndTimestamp).toBeGreaterThan(0)
}
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
).toEqual(expect.any(Number))
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
).toEqual(expect.any(Number))
// We need to clean up the resources after our test
{
workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE,
workerChoiceStrategyOptions: {
- runTime: { median: true }
- }
+ runTime: { median: true },
+ },
}
)
// TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ failed: 0,
},
runTime: expect.objectContaining({
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer),
+ }),
+ waitTime: expect.objectContaining({
+ history: expect.any(CircularBuffer),
}),
- waitTime: {
- history: new CircularArray()
- },
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),
+ }),
+ }),
})
expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
} else {
expect(workerNode.usage.runTime.median).toBeGreaterThan(0)
}
+ if (workerNode.usage.waitTime.aggregate == null) {
+ expect(workerNode.usage.waitTime.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.waitTime.aggregate).toBeGreaterThan(0)
+ }
+ if (workerNode.usage.waitTime.median == null) {
+ expect(workerNode.usage.waitTime.median).toBeUndefined()
+ } else {
+ expect(workerNode.usage.waitTime.median).toBeGreaterThan(0)
+ }
if (workerNode.usage.elu.active.aggregate == null) {
expect(workerNode.usage.elu.active.aggregate).toBeUndefined()
} else {
expect(workerNode.strategyData.virtualTaskEndTimestamp).toBeGreaterThan(0)
}
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
).toEqual(expect.any(Number))
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
).toEqual(expect.any(Number))
// We need to clean up the resources after our test
await pool.destroy()
})
- it('Verify FAIR_SHARE strategy internals are resets after setting it', async () => {
+ it("Verify FAIR_SHARE strategy internals aren't reset after setting it", async () => {
const workerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE
let pool = new FixedThreadPool(
max,
)
for (const workerNode of pool.workerNodes) {
workerNode.strategyData = {
- virtualTaskEndTimestamp: performance.now()
+ virtualTaskEndTimestamp: performance.now(),
}
}
pool.setWorkerChoiceStrategy(workerChoiceStrategy)
for (const workerNode of pool.workerNodes) {
- expect(workerNode.strategyData.virtualTaskEndTimestamp).toBeUndefined()
+ expect(workerNode.strategyData.virtualTaskEndTimestamp).toBeGreaterThan(0)
}
await pool.destroy()
pool = new DynamicThreadPool(
)
for (const workerNode of pool.workerNodes) {
workerNode.strategyData = {
- virtualTaskEndTimestamp: performance.now()
+ virtualTaskEndTimestamp: performance.now(),
}
}
pool.setWorkerChoiceStrategy(workerChoiceStrategy)
for (const workerNode of pool.workerNodes) {
- expect(workerNode.strategyData.virtualTaskEndTimestamp).toBeUndefined()
+ expect(workerNode.strategyData.virtualTaskEndTimestamp).toBeGreaterThan(0)
}
// We need to clean up the resources after our test
await pool.destroy()
'./tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
+ expect(pool.workerChoiceStrategiesContext.getPolicy()).toStrictEqual({
dynamicWorkerUsage: false,
- dynamicWorkerReady: true
+ dynamicWorkerReady: true,
})
await pool.destroy()
pool = new DynamicThreadPool(
'./tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
+ expect(pool.workerChoiceStrategiesContext.getPolicy()).toStrictEqual({
dynamicWorkerUsage: false,
- dynamicWorkerReady: true
+ dynamicWorkerReady: true,
})
// We need to clean up the resources after our test
await pool.destroy()
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ pool.workerChoiceStrategiesContext.getTaskStatisticsRequirements()
).toStrictEqual({
runTime: {
aggregate: true,
average: true,
- median: false
+ median: false,
},
waitTime: {
- aggregate: false,
- average: false,
- median: false
+ aggregate: true,
+ average: true,
+ median: false,
},
elu: {
aggregate: false,
average: false,
- median: false
- }
+ median: false,
+ },
})
await pool.destroy()
pool = new DynamicThreadPool(
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ pool.workerChoiceStrategiesContext.getTaskStatisticsRequirements()
).toStrictEqual({
runTime: {
aggregate: true,
average: true,
- median: false
+ median: false,
},
waitTime: {
- aggregate: false,
- average: false,
- median: false
+ aggregate: true,
+ average: true,
+ median: false,
},
elu: {
aggregate: false,
average: false,
- median: false
- }
+ median: false,
+ },
})
// We need to clean up the resources after our test
await pool.destroy()
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ failed: 0,
},
runTime: expect.objectContaining({
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer),
+ }),
+ waitTime: expect.objectContaining({
+ history: expect.any(CircularBuffer),
}),
- waitTime: {
- history: new CircularArray()
- },
elu: {
idle: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
active: {
- history: new CircularArray()
- }
- }
+ history: expect.any(CircularBuffer),
+ },
+ },
})
expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
} else {
expect(workerNode.usage.runTime.average).toBeGreaterThan(0)
}
+ if (workerNode.usage.waitTime.aggregate == null) {
+ expect(workerNode.usage.waitTime.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.waitTime.aggregate).toBeGreaterThan(0)
+ }
+ if (workerNode.usage.waitTime.average == null) {
+ expect(workerNode.usage.waitTime.average).toBeUndefined()
+ } else {
+ expect(workerNode.usage.waitTime.average).toBeGreaterThan(0)
+ }
}
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
- ).toBe(0)
+ ).toEqual(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).workerNodeVirtualTaskRunTime
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
+ ).workerNodeVirtualTaskExecutionTime
).toBeGreaterThanOrEqual(0)
// We need to clean up the resources after our test
await pool.destroy()
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ failed: 0,
},
runTime: expect.objectContaining({
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer),
+ }),
+ waitTime: expect.objectContaining({
+ history: expect.any(CircularBuffer),
}),
- waitTime: {
- history: new CircularArray()
- },
elu: {
idle: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
active: {
- history: new CircularArray()
- }
- }
+ history: expect.any(CircularBuffer),
+ },
+ },
})
expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
} else {
expect(workerNode.usage.runTime.average).toBeGreaterThan(0)
}
+ if (workerNode.usage.waitTime.aggregate == null) {
+ expect(workerNode.usage.waitTime.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.waitTime.aggregate).toBeGreaterThan(0)
+ }
+ if (workerNode.usage.waitTime.average == null) {
+ expect(workerNode.usage.waitTime.average).toBeUndefined()
+ } else {
+ expect(workerNode.usage.waitTime.average).toBeGreaterThan(0)
+ }
}
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
- ).toBe(0)
+ ).toEqual(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
- ).toBe(0)
+ ).toEqual(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).workerNodeVirtualTaskRunTime
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
+ ).workerNodeVirtualTaskExecutionTime
).toBeGreaterThanOrEqual(0)
// We need to clean up the resources after our test
await pool.destroy()
{
workerChoiceStrategy: WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN,
workerChoiceStrategyOptions: {
- runTime: { median: true }
- }
+ runTime: { median: true },
+ },
}
)
// TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ failed: 0,
},
runTime: expect.objectContaining({
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer),
+ }),
+ waitTime: expect.objectContaining({
+ history: expect.any(CircularBuffer),
}),
- waitTime: {
- history: new CircularArray()
- },
elu: {
idle: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
active: {
- history: new CircularArray()
- }
- }
+ history: expect.any(CircularBuffer),
+ },
+ },
})
expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
} else {
expect(workerNode.usage.runTime.median).toBeGreaterThan(0)
}
+ if (workerNode.usage.waitTime.aggregate == null) {
+ expect(workerNode.usage.waitTime.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.waitTime.aggregate).toBeGreaterThan(0)
+ }
+ if (workerNode.usage.waitTime.median == null) {
+ expect(workerNode.usage.waitTime.median).toBeUndefined()
+ } else {
+ expect(workerNode.usage.waitTime.median).toBeGreaterThan(0)
+ }
}
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
- ).toBe(0)
+ ).toEqual(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
- ).toBe(0)
+ ).toEqual(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).workerNodeVirtualTaskRunTime
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
+ ).workerNodeVirtualTaskExecutionTime
).toBeGreaterThanOrEqual(0)
// We need to clean up the resources after our test
await pool.destroy()
})
- it('Verify WEIGHTED_ROUND_ROBIN strategy internals are resets after setting it', async () => {
+ it("Verify WEIGHTED_ROUND_ROBIN strategy internals aren't reset after setting it", async () => {
const workerChoiceStrategy = WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.mjs'
+ './tests/worker-files/thread/testWorker.mjs',
+ { workerChoiceStrategy }
)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).nextWorkerNodeKey
- ).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).previousWorkerNodeKey
- ).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).workerNodeVirtualTaskRunTime
- ).toBeDefined()
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).nextWorkerNodeKey = randomInt(1, max - 1)
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).previousWorkerNodeKey = randomInt(1, max - 1)
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).workerNodeVirtualTaskRunTime = randomInt(100, 1000)
pool.setWorkerChoiceStrategy(workerChoiceStrategy)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
- ).toBe(0)
+ ).toBeGreaterThan(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
- ).toBe(0)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
).toBeGreaterThan(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).workerNodeVirtualTaskRunTime
- ).toBe(0)
+ ).toBeGreaterThan(99)
await pool.destroy()
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.mjs'
+ './tests/worker-files/thread/testWorker.mjs',
+ { workerChoiceStrategy }
)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).nextWorkerNodeKey
- ).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).previousWorkerNodeKey
- ).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).workerNodeVirtualTaskRunTime
- ).toBeDefined()
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).nextWorkerNodeKey = randomInt(1, max - 1)
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).previousWorkerNodeKey = randomInt(1, max - 1)
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).workerNodeVirtualTaskRunTime = randomInt(100, 1000)
pool.setWorkerChoiceStrategy(workerChoiceStrategy)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
- ).toBe(0)
+ ).toBeGreaterThan(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
- ).toBe(0)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
).toBeGreaterThan(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).workerNodeVirtualTaskRunTime
- ).toBe(0)
+ ).toBeGreaterThan(99)
// We need to clean up the resources after our test
await pool.destroy()
})
'./tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
+ expect(pool.workerChoiceStrategiesContext.getPolicy()).toStrictEqual({
dynamicWorkerUsage: false,
- dynamicWorkerReady: true
+ dynamicWorkerReady: true,
})
await pool.destroy()
pool = new DynamicThreadPool(
'./tests/worker-files/thread/testWorker.mjs',
{ workerChoiceStrategy }
)
- expect(pool.workerChoiceStrategyContext.getStrategyPolicy()).toStrictEqual({
+ expect(pool.workerChoiceStrategiesContext.getPolicy()).toStrictEqual({
dynamicWorkerUsage: false,
- dynamicWorkerReady: true
+ dynamicWorkerReady: true,
})
// We need to clean up the resources after our test
await pool.destroy()
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ pool.workerChoiceStrategiesContext.getTaskStatisticsRequirements()
).toStrictEqual({
runTime: {
aggregate: true,
average: true,
- median: false
+ median: false,
},
waitTime: {
- aggregate: false,
- average: false,
- median: false
+ aggregate: true,
+ average: true,
+ median: false,
},
elu: {
aggregate: false,
average: false,
- median: false
- }
+ median: false,
+ },
})
await pool.destroy()
pool = new DynamicThreadPool(
{ workerChoiceStrategy }
)
expect(
- pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
+ pool.workerChoiceStrategiesContext.getTaskStatisticsRequirements()
).toStrictEqual({
runTime: {
aggregate: true,
average: true,
- median: false
+ median: false,
},
waitTime: {
- aggregate: false,
- average: false,
- median: false
+ aggregate: true,
+ average: true,
+ median: false,
},
elu: {
aggregate: false,
average: false,
- median: false
- }
+ median: false,
+ },
})
// We need to clean up the resources after our test
await pool.destroy()
'./tests/worker-files/thread/testWorker.mjs',
{
workerChoiceStrategy:
- WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN
+ WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN,
}
)
// TODO: Create a better test to cover `InterleavedWeightedRoundRobinWorkerChoiceStrategy#choose`
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ failed: 0,
},
runTime: expect.objectContaining({
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer),
+ }),
+ waitTime: expect.objectContaining({
+ history: expect.any(CircularBuffer),
}),
- waitTime: {
- history: new CircularArray()
- },
elu: {
idle: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
active: {
- history: new CircularArray()
- }
- }
+ history: expect.any(CircularBuffer),
+ },
+ },
})
expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
max * maxMultiplier
)
+ if (workerNode.usage.runTime.aggregate == null) {
+ expect(workerNode.usage.runTime.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.runTime.aggregate).toBeGreaterThan(0)
+ }
+ if (workerNode.usage.runTime.average == null) {
+ expect(workerNode.usage.runTime.average).toBeUndefined()
+ } else {
+ expect(workerNode.usage.runTime.average).toBeGreaterThan(0)
+ }
+ if (workerNode.usage.waitTime.aggregate == null) {
+ expect(workerNode.usage.waitTime.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.waitTime.aggregate).toBeGreaterThan(0)
+ }
+ if (workerNode.usage.waitTime.average == null) {
+ expect(workerNode.usage.waitTime.average).toBeUndefined()
+ } else {
+ expect(workerNode.usage.waitTime.average).toBeGreaterThan(0)
+ }
}
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).roundId
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).workerNodeId
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
- ).toEqual(expect.any(Number))
+ ).toEqual(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).roundWeights
- ).toStrictEqual([
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ])
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
+ ).roundWeights.length
+ ).toBe(1)
+ expect(
+ Number.isSafeInteger(
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
+ ).roundWeights[0]
+ )
+ ).toBe(true)
// We need to clean up the resources after our test
await pool.destroy()
})
'./tests/worker-files/thread/testWorker.mjs',
{
workerChoiceStrategy:
- WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN
+ WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN,
}
)
// TODO: Create a better test to cover `InterleavedWeightedRoundRobinWorkerChoiceStrategy#choose`
executing: 0,
queued: 0,
maxQueued: 0,
+ sequentiallyStolen: 0,
stolen: 0,
- failed: 0
+ failed: 0,
},
runTime: expect.objectContaining({
- history: expect.any(CircularArray)
+ history: expect.any(CircularBuffer),
+ }),
+ waitTime: expect.objectContaining({
+ history: expect.any(CircularBuffer),
}),
- waitTime: {
- history: new CircularArray()
- },
elu: {
idle: {
- history: new CircularArray()
+ history: expect.any(CircularBuffer),
},
active: {
- history: new CircularArray()
- }
- }
+ history: expect.any(CircularBuffer),
+ },
+ },
})
expect(workerNode.usage.tasks.executed).toBeGreaterThanOrEqual(0)
expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual(
max * maxMultiplier
)
+ if (workerNode.usage.runTime.aggregate == null) {
+ expect(workerNode.usage.runTime.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.runTime.aggregate).toBeGreaterThan(0)
+ }
+ if (workerNode.usage.runTime.average == null) {
+ expect(workerNode.usage.runTime.average).toBeUndefined()
+ } else {
+ expect(workerNode.usage.runTime.average).toBeGreaterThan(0)
+ }
+ if (workerNode.usage.waitTime.aggregate == null) {
+ expect(workerNode.usage.waitTime.aggregate).toBeUndefined()
+ } else {
+ expect(workerNode.usage.waitTime.aggregate).toBeGreaterThan(0)
+ }
+ if (workerNode.usage.waitTime.average == null) {
+ expect(workerNode.usage.waitTime.average).toBeUndefined()
+ } else {
+ expect(workerNode.usage.waitTime.average).toBeGreaterThan(0)
+ }
}
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeGreaterThan(0)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).roundId
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).workerNodeId
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
).toBe(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
- ).toEqual(expect.any(Number))
+ ).toEqual(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).roundWeights
- ).toStrictEqual([
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ])
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
+ ).roundWeights.length
+ ).toBe(1)
+ expect(
+ Number.isSafeInteger(
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
+ ).roundWeights[0]
+ )
+ ).toBe(true)
// We need to clean up the resources after our test
await pool.destroy()
})
- it('Verify INTERLEAVED_WEIGHTED_ROUND_ROBIN strategy internals are resets after setting it', async () => {
+ it("Verify INTERLEAVED_WEIGHTED_ROUND_ROBIN strategy internals aren't reset after setting it", async () => {
const workerChoiceStrategy =
WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN
let pool = new FixedThreadPool(
max,
- './tests/worker-files/thread/testWorker.mjs'
+ './tests/worker-files/thread/testWorker.mjs',
+ { workerChoiceStrategy }
)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).roundId
- ).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).workerNodeId
- ).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).nextWorkerNodeKey
- ).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).previousWorkerNodeKey
- ).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).roundWeights
- ).toBeDefined()
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).roundId = randomInt(1, max - 1)
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).workerNodeId = randomInt(1, max - 1)
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).nextWorkerNodeKey = randomInt(1, max - 1)
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).previousWorkerNodeKey = randomInt(1, max - 1)
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).roundWeights = [randomInt(1, max - 1), randomInt(1, max - 1)]
pool.setWorkerChoiceStrategy(workerChoiceStrategy)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).roundId
- ).toBe(0)
+ ).toBeGreaterThan(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).workerNodeId
- ).toBe(0)
+ ).toBeGreaterThan(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
- ).toBe(0)
+ ).toBeGreaterThan(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
- ).toBe(0)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
).toBeGreaterThan(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).roundWeights
- ).toStrictEqual([
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ])
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
+ ).roundWeights.length
+ ).toBeGreaterThan(1)
+ expect(
+ Number.isSafeInteger(
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
+ ).roundWeights[0]
+ )
+ ).toBe(true)
await pool.destroy()
pool = new DynamicThreadPool(
min,
max,
- './tests/worker-files/thread/testWorker.mjs'
+ './tests/worker-files/thread/testWorker.mjs',
+ { workerChoiceStrategy }
)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).roundId
- ).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).workerNodeId
- ).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).nextWorkerNodeKey
- ).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).previousWorkerNodeKey
- ).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).defaultWorkerWeight
- ).toBeDefined()
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- workerChoiceStrategy
- ).roundWeights
- ).toBeDefined()
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).roundId = randomInt(1, max - 1)
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).workerNodeId = randomInt(1, max - 1)
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).nextWorkerNodeKey = randomInt(1, max - 1)
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).previousWorkerNodeKey = randomInt(1, max - 1)
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ workerChoiceStrategy
+ ).roundWeights = [randomInt(1, max - 1), randomInt(1, max - 1)]
pool.setWorkerChoiceStrategy(workerChoiceStrategy)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).roundId
- ).toBe(0)
+ ).toBeGreaterThan(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).workerNodeId
- ).toBe(0)
+ ).toBeGreaterThan(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).nextWorkerNodeKey
- ).toBe(0)
+ ).toBeGreaterThan(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
).previousWorkerNodeKey
- ).toBe(0)
- expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
).toBeGreaterThan(0)
expect(
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).roundWeights
- ).toStrictEqual([
- pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
- pool.workerChoiceStrategyContext.workerChoiceStrategy
- ).defaultWorkerWeight
- ])
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
+ ).roundWeights.length
+ ).toBeGreaterThan(1)
+ expect(
+ Number.isSafeInteger(
+ pool.workerChoiceStrategiesContext.workerChoiceStrategies.get(
+ pool.workerChoiceStrategiesContext.defaultWorkerChoiceStrategy
+ ).roundWeights[0]
+ )
+ ).toBe(true)
// We need to clean up the resources after our test
await pool.destroy()
})