"benchmark": "pnpm build && node -r source-map-support/register benchmarks/internal/bench.mjs",
"benchmark:debug": "pnpm build && node -r source-map-support/register --inspect benchmarks/internal/bench.mjs",
"benchmark:prod": "pnpm build:prod && node benchmarks/internal/bench.mjs",
- "test": "pnpm build --environment SOURCEMAP:false && c8 mocha 'tests/**/*.test.js'",
- "test:debug": "pnpm build && mocha --no-parallel --inspect 'tests/**/*.test.js'",
+ "test": "pnpm build --environment SOURCEMAP:false && c8 mocha 'tests/**/*.test.mjs'",
+ "test:debug": "pnpm build && mocha --no-parallel --inspect 'tests/**/*.test.mjs'",
"coverage": "c8 report --reporter=lcov",
"coverage:html": "c8 report --reporter=html",
"format": "biome format . --write; ts-standard . --fix",
-const { expect } = require('expect')
-const {
+import { expect } from 'expect'
+import {
CircularArray,
DEFAULT_CIRCULAR_ARRAY_SIZE
-} = require('../lib/circular-array')
+} from '../lib/circular-array.js'
describe('Circular array test suite', () => {
it('Verify that circular array can be instantiated', () => {
-const { expect } = require('expect')
-const { Deque } = require('../lib/deque')
+import { expect } from 'expect'
+import { Deque } from '../lib/deque.js'
describe('Deque test suite', () => {
it('Verify push() behavior', () => {
-const { EventEmitterAsyncResource } = require('node:events')
-const { expect } = require('expect')
-const sinon = require('sinon')
-const {
+import { EventEmitterAsyncResource } from 'node:events'
+import { readFileSync } from 'node:fs'
+import { expect } from 'expect'
+import { restore, stub } from 'sinon'
+import {
DynamicClusterPool,
DynamicThreadPool,
FixedClusterPool,
PoolTypes,
WorkerChoiceStrategies,
WorkerTypes
-} = require('../../lib')
-const { CircularArray } = require('../../lib/circular-array')
-const { Deque } = require('../../lib/deque')
-const { DEFAULT_TASK_NAME } = require('../../lib/utils')
-const { version } = require('../../package.json')
-const { waitPoolEvents } = require('../test-utils')
-const { WorkerNode } = require('../../lib/pools/worker-node')
+} from '../../lib/index.js'
+import { CircularArray } from '../../lib/circular-array.js'
+import { Deque } from '../../lib/deque.js'
+import { DEFAULT_TASK_NAME } from '../../lib/utils.js'
+import { waitPoolEvents } from '../test-utils.js'
+import { WorkerNode } from '../../lib/pools/worker-node.js'
describe('Abstract pool test suite', () => {
+ const version = JSON.parse(readFileSync('./package.json', 'utf8')).version
const numberOfWorkers = 2
class StubPoolWithIsMain extends FixedThreadPool {
isMain () {
}
afterEach(() => {
- sinon.restore()
+ restore()
})
it('Simulate pool creation from a non main thread/process', () => {
enableTasksQueue: true
}
)
- sinon.stub(pool, 'hasBackPressure').returns(true)
+ stub(pool, 'hasBackPressure').returns(true)
expect(pool.emitter.eventNames()).toStrictEqual([])
const promises = new Set()
let poolBackPressure = 0
-const { expect } = require('expect')
-const { DynamicClusterPool, PoolEvents } = require('../../../lib')
-const { TaskFunctions } = require('../../test-types')
-const { sleep, waitWorkerEvents } = require('../../test-utils')
+import { expect } from 'expect'
+import { DynamicClusterPool, PoolEvents } from '../../../lib/index.js'
+import { TaskFunctions } from '../../test-types.js'
+import { sleep, waitWorkerEvents } from '../../test-utils.js'
describe('Dynamic cluster pool test suite', () => {
const min = 1
-const { expect } = require('expect')
-const { FixedClusterPool, PoolEvents } = require('../../../lib')
-const { TaskFunctions } = require('../../test-types')
-const { waitPoolEvents, waitWorkerEvents } = require('../../test-utils')
-const { DEFAULT_TASK_NAME } = require('../../../lib/utils')
+import { expect } from 'expect'
+import { FixedClusterPool, PoolEvents } from '../../../lib/index.js'
+import { TaskFunctions } from '../../test-types.js'
+import { waitPoolEvents, waitWorkerEvents } from '../../test-utils.js'
+import { DEFAULT_TASK_NAME } from '../../../lib/utils.js'
describe('Fixed cluster pool test suite', () => {
const numberOfWorkers = 8
-const { expect } = require('expect')
-const {
+import { expect } from 'expect'
+import {
DynamicClusterPool,
DynamicThreadPool,
FixedClusterPool,
FixedThreadPool,
WorkerChoiceStrategies
-} = require('../../../lib')
-const { CircularArray } = require('../../../lib/circular-array')
+} from '../../../lib/index.js'
+import { CircularArray } from '../../../lib/circular-array.js'
describe('Selection strategies test suite', () => {
const min = 0
-const { expect } = require('expect')
-const sinon = require('sinon')
-const { FixedThreadPool } = require('../../../lib')
-const {
- WeightedRoundRobinWorkerChoiceStrategy
-} = require('../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy')
-const { generateRandomInteger } = require('../../test-utils')
+import { expect } from 'expect'
+import { restore } from 'sinon'
+import { FixedThreadPool } from '../../../lib/index.js'
+import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.js'
+import { generateRandomInteger } from '../../test-utils.js'
describe('Weighted round robin strategy worker choice strategy test suite', () => {
// const min = 1
})
afterEach(() => {
- sinon.restore()
+ restore()
})
after(async () => {
-const { expect } = require('expect')
-const sinon = require('sinon')
-const {
- FixedThreadPool,
+import { expect } from 'expect'
+import { createStubInstance, restore, stub } from 'sinon'
+import {
DynamicThreadPool,
+ FixedThreadPool,
WorkerChoiceStrategies
-} = require('../../../lib')
-const {
- WorkerChoiceStrategyContext
-} = require('../../../lib/pools/selection-strategies/worker-choice-strategy-context')
-const {
- RoundRobinWorkerChoiceStrategy
-} = require('../../../lib/pools/selection-strategies/round-robin-worker-choice-strategy')
-const {
- LeastUsedWorkerChoiceStrategy
-} = require('../../../lib/pools/selection-strategies/least-used-worker-choice-strategy')
-const {
- LeastBusyWorkerChoiceStrategy
-} = require('../../../lib/pools/selection-strategies/least-busy-worker-choice-strategy')
-const {
- LeastEluWorkerChoiceStrategy
-} = require('../../../lib/pools/selection-strategies/least-elu-worker-choice-strategy')
-const {
- FairShareWorkerChoiceStrategy
-} = require('../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy')
-const {
- WeightedRoundRobinWorkerChoiceStrategy
-} = require('../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy')
-const {
- InterleavedWeightedRoundRobinWorkerChoiceStrategy
-} = require('../../../lib/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy')
+} from '../../../lib/index.js'
+import { WorkerChoiceStrategyContext } from '../../../lib/pools/selection-strategies/worker-choice-strategy-context.js'
+import { RoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/round-robin-worker-choice-strategy.js'
+import { LeastUsedWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-used-worker-choice-strategy.js'
+import { LeastBusyWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-busy-worker-choice-strategy.js'
+import { LeastEluWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-elu-worker-choice-strategy.js'
+import { FairShareWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy.js'
+import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.js'
+import { InterleavedWeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.js'
describe('Worker choice strategy context test suite', () => {
const min = 1
})
afterEach(() => {
- sinon.restore()
+ restore()
})
after(async () => {
const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
fixedPool
)
- const WorkerChoiceStrategyStub = sinon.createStubInstance(
+ const WorkerChoiceStrategyStub = createStubInstance(
RoundRobinWorkerChoiceStrategy,
{
- choose: sinon.stub().returns(0)
+ choose: stub().returns(0)
}
)
expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
fixedPool
)
- const WorkerChoiceStrategyUndefinedStub = sinon.createStubInstance(
+ const WorkerChoiceStrategyUndefinedStub = createStubInstance(
RoundRobinWorkerChoiceStrategy,
{
- choose: sinon.stub().returns(undefined)
+ choose: stub().returns(undefined)
}
)
- const WorkerChoiceStrategyNullStub = sinon.createStubInstance(
+ const WorkerChoiceStrategyNullStub = createStubInstance(
RoundRobinWorkerChoiceStrategy,
{
- choose: sinon.stub().returns(null)
+ choose: stub().returns(null)
}
)
expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
dynamicPool
)
- const WorkerChoiceStrategyStub = sinon.createStubInstance(
+ const WorkerChoiceStrategyStub = createStubInstance(
RoundRobinWorkerChoiceStrategy,
{
- choose: sinon.stub().returns(0)
+ choose: stub().returns(0)
}
)
expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
-const { expect } = require('expect')
-const { DynamicThreadPool, PoolEvents } = require('../../../lib')
-const { TaskFunctions } = require('../../test-types')
-const { sleep, waitWorkerEvents } = require('../../test-utils')
+import { expect } from 'expect'
+import { DynamicThreadPool, PoolEvents } from '../../../lib/index.js'
+import { TaskFunctions } from '../../test-types.js'
+import { sleep, waitWorkerEvents } from '../../test-utils.js'
describe('Dynamic thread pool test suite', () => {
const min = 1
-const { expect } = require('expect')
-const { FixedThreadPool, PoolEvents } = require('../../../lib')
-const { TaskFunctions } = require('../../test-types')
-const { waitPoolEvents, waitWorkerEvents } = require('../../test-utils')
-const { DEFAULT_TASK_NAME } = require('../../../lib/utils')
+import { expect } from 'expect'
+import { FixedThreadPool, PoolEvents } from '../../../lib/index.js'
+import { TaskFunctions } from '../../test-types.js'
+import { waitPoolEvents, waitWorkerEvents } from '../../test-utils.js'
+import { DEFAULT_TASK_NAME } from '../../../lib/utils.js'
describe('Fixed thread pool test suite', () => {
const numberOfThreads = 6
-const { expect } = require('expect')
-const {
- DEFAULT_CIRCULAR_ARRAY_SIZE,
- CircularArray
-} = require('../../lib/circular-array')
-const { updateMeasurementStatistics } = require('../../lib/pools/utils')
+import { expect } from 'expect'
+import {
+ CircularArray,
+ DEFAULT_CIRCULAR_ARRAY_SIZE
+} from '../../lib/circular-array.js'
+import { updateMeasurementStatistics } from '../../lib/pools/utils.js'
describe('Pool utils test suite', () => {
it('Verify updateMeasurementStatistics() behavior', () => {
-const { MessageChannel, Worker } = require('node:worker_threads')
-const cluster = require('node:cluster')
-const { expect } = require('expect')
-const { WorkerNode } = require('../../lib/pools/worker-node')
-const { WorkerTypes } = require('../../lib')
-const { CircularArray } = require('../../lib/circular-array')
-const { Deque } = require('../../lib/deque')
-const { DEFAULT_TASK_NAME } = require('../../lib/utils')
+import { MessageChannel, Worker } from 'node:worker_threads'
+import cluster from 'node:cluster'
+import { expect } from 'expect'
+import { WorkerNode } from '../../lib/pools/worker-node.js'
+import { WorkerTypes } from '../../lib/index.js'
+import { CircularArray } from '../../lib/circular-array.js'
+import { Deque } from '../../lib/deque.js'
+import { DEFAULT_TASK_NAME } from '../../lib/utils.js'
describe('Worker node test suite', () => {
const threadWorker = new Worker('./tests/worker-files/thread/testWorker.js')
-const { randomInt } = require('node:crypto')
-const { Worker } = require('node:worker_threads')
-const cluster = require('node:cluster')
-const os = require('node:os')
-const { expect } = require('expect')
-const {
+import { Worker } from 'node:worker_threads'
+import cluster from 'node:cluster'
+import os from 'node:os'
+import { randomInt } from 'node:crypto'
+import { expect } from 'expect'
+import {
DEFAULT_MEASUREMENT_STATISTICS_REQUIREMENTS,
DEFAULT_TASK_NAME,
DEFAULT_WORKER_CHOICE_STRATEGY_OPTIONS,
availableParallelism,
average,
exponentialDelay,
- getWorkerType,
getWorkerId,
+ getWorkerType,
isAsyncFunction,
isKillBehavior,
isPlainObject,
round,
secureRandom,
sleep
-} = require('../lib/utils')
-const { KillBehaviors, WorkerTypes } = require('../lib')
+} from '../lib/utils.js'
+import { KillBehaviors, WorkerTypes } from '../lib/index.js'
describe('Utils test suite', () => {
it('Verify DEFAULT_TASK_NAME value', () => {
-const { expect } = require('expect')
-const sinon = require('sinon')
-const { ClusterWorker, KillBehaviors, ThreadWorker } = require('../../lib')
-const { DEFAULT_TASK_NAME, EMPTY_FUNCTION } = require('../../lib/utils')
+import { expect } from 'expect'
+import { restore, stub } from 'sinon'
+import { ClusterWorker, KillBehaviors, ThreadWorker } from '../../lib/index.js'
+import { DEFAULT_TASK_NAME, EMPTY_FUNCTION } from '../../lib/utils.js'
describe('Abstract worker test suite', () => {
class StubWorkerWithMainWorker extends ThreadWorker {
}
afterEach(() => {
- sinon.restore()
+ restore()
})
it('Verify worker options default values', () => {
it('Verify that sync kill handler is called when worker is killed', () => {
const worker = new ClusterWorker(() => {}, {
- killHandler: sinon.stub().returns()
+ killHandler: stub().returns()
})
worker.isMain = false
- worker.getMainWorker = sinon.stub().returns({
+ worker.getMainWorker = stub().returns({
id: 1,
- send: sinon.stub().returns()
+ send: stub().returns()
})
worker.handleKillMessage()
expect(worker.getMainWorker().send.calledOnce).toBe(true)
})
it('Verify that async kill handler is called when worker is killed', () => {
- const killHandlerStub = sinon.stub().returns()
+ const killHandlerStub = stub().returns()
const worker = new ClusterWorker(() => {}, {
killHandler: async () => Promise.resolve(killHandlerStub())
})
status: false,
error: new TypeError('name parameter is an empty string')
})
- worker.getMainWorker = sinon.stub().returns({
+ worker.getMainWorker = stub().returns({
id: 1,
- send: sinon.stub().returns()
+ send: stub().returns()
})
expect(worker.taskFunctions.get(DEFAULT_TASK_NAME)).toBeInstanceOf(Function)
expect(worker.taskFunctions.get('fn1')).toBeInstanceOf(Function)
-const { expect } = require('expect')
-const { ClusterWorker } = require('../../lib')
+import { expect } from 'expect'
+import { ClusterWorker } from '../../lib/index.js'
describe('Cluster worker test suite', () => {
let numberOfMessagesSent = 0
-const { expect } = require('expect')
-const { ThreadWorker } = require('../../lib')
+import { expect } from 'expect'
+import { ThreadWorker } from '../../lib/index.js'
describe('Thread worker test suite', () => {
let numberOfMessagesPosted = 0