import {
DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
DEFAULT_TASK_NAME,
- DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS,
EMPTY_FUNCTION,
availableParallelism,
average,
+ buildInternalWorkerChoiceStrategyOptions,
exponentialDelay,
getWorkerId,
getWorkerType,
round,
secureRandom,
sleep
-} from '../lib/utils.js'
-import { KillBehaviors, WorkerTypes } from '../lib/index.js'
+} from '../lib/utils.cjs'
+import { KillBehaviors, WorkerTypes } from '../lib/index.cjs'
describe('Utils test suite', () => {
it('Verify DEFAULT_TASK_NAME value', () => {
expect(EMPTY_FUNCTION).toStrictEqual(expect.any(Function))
})
- it('Verify DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS values', () => {
- expect(DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS).toStrictEqual({
- retries: 6,
- runTime: { median: false },
- waitTime: { median: false },
- elu: { median: false }
- })
- })
-
it('Verify DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS values', () => {
expect(DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS).toStrictEqual({
aggregate: false,
it('Verify sleep() behavior', async () => {
const start = performance.now()
- await sleep(1000)
+ const sleepMs = 1000
+ await sleep(sleepMs)
const elapsed = performance.now() - start
- expect(elapsed).toBeGreaterThanOrEqual(1000)
+ expect(elapsed).toBeGreaterThanOrEqual(sleepMs - 1)
})
it('Verify exponentialDelay() behavior', () => {
expect(max(1, 1)).toBe(1)
})
+ it('Verify buildInternalWorkerChoiceStrategyOptions() behavior', () => {
+ const poolMaxSize = 10
+ const internalWorkerChoiceStrategyOptions =
+ buildInternalWorkerChoiceStrategyOptions(poolMaxSize)
+ expect(internalWorkerChoiceStrategyOptions).toStrictEqual({
+ retries:
+ poolMaxSize +
+ Object.keys(internalWorkerChoiceStrategyOptions.weights).length,
+ runTime: { median: false },
+ waitTime: { median: false },
+ elu: { median: false },
+ weights: expect.objectContaining({
+ 0: expect.any(Number),
+ [poolMaxSize - 1]: expect.any(Number)
+ })
+ })
+ })
+
// it('Verify once()', () => {
// let called = 0
// const fn = () => ++called