-export const TaskFunctions = {
+const TaskFunctions = {
jsonIntegerSerialization: 'jsonIntegerSerialization',
fibonacci: 'fibonacci',
factorial: 'factorial',
readWriteFiles: 'readWriteFiles'
}
+
+module.exports = { TaskFunctions }
-import crypto from 'node:crypto'
-import assert from 'node:assert'
-import fs from 'node:fs'
-import Benchmark from 'benchmark'
-import {
+const crypto = require('node:crypto')
+const assert = require('node:assert')
+const fs = require('node:fs')
+const Benchmark = require('benchmark')
+const {
DynamicClusterPool,
DynamicThreadPool,
FixedClusterPool,
PoolTypes,
WorkerChoiceStrategies,
WorkerTypes
-} from '../lib/index.mjs'
-import { TaskFunctions } from './benchmarks-types.mjs'
+} = require('../lib/index.js')
+const { TaskFunctions } = require('./benchmarks-types.js')
-export const buildPoolifierPool = (
- workerType,
- poolType,
- poolSize,
- poolOptions
-) => {
+const buildPoolifierPool = (workerType, poolType, poolSize, poolOptions) => {
switch (poolType) {
case PoolTypes.fixed:
switch (workerType) {
case WorkerTypes.cluster:
return new FixedClusterPool(
poolSize,
- './benchmarks/internal/cluster-worker.mjs',
+ './benchmarks/internal/cluster-worker.js',
poolOptions
)
}
return new DynamicClusterPool(
Math.floor(poolSize / 2),
poolSize,
- './benchmarks/internal/cluster-worker.mjs',
+ './benchmarks/internal/cluster-worker.js',
poolOptions
)
}
}
}
-export const runPoolifierPool = async (
- pool,
- { taskExecutions, workerData }
-) => {
+const runPoolifierPool = async (pool, { taskExecutions, workerData }) => {
return await new Promise((resolve, reject) => {
let executions = 0
for (let i = 1; i <= taskExecutions; i++) {
})
}
-export const runPoolifierPoolBenchmark = async (
+const runPoolifierPoolBenchmark = async (
name,
pool,
{ taskExecutions, workerData }
})
}
-export const LIST_FORMATTER = new Intl.ListFormat('en-US', {
+const LIST_FORMATTER = new Intl.ListFormat('en-US', {
style: 'long',
type: 'conjunction'
})
-export const generateRandomInteger = (
- max = Number.MAX_SAFE_INTEGER,
- min = 0
-) => {
+const generateRandomInteger = (max = Number.MAX_SAFE_INTEGER, min = 0) => {
if (max < min || max < 0 || min < 0) {
throw new RangeError('Invalid interval')
}
return { ok: 1 }
}
-export const executeTaskFunction = data => {
+const executeTaskFunction = data => {
switch (data.function) {
case TaskFunctions.jsonIntegerSerialization:
return jsonIntegerSerialization(data.taskSize || 1000)
throw new Error('Unknown task function')
}
}
+
+module.exports = {
+ LIST_FORMATTER,
+ buildPoolifierPool,
+ executeTaskFunction,
+ generateRandomInteger,
+ runPoolifierPoolBenchmark
+}
WorkerTypes,
availableParallelism
} from '../../lib/index.mjs'
-import { TaskFunctions } from '../benchmarks-types.mjs'
+import { TaskFunctions } from '../benchmarks-types.js'
import {
buildPoolifierPool,
runPoolifierPoolBenchmark
-} from '../benchmarks-utils.mjs'
+} from '../benchmarks-utils.js'
const poolSize = availableParallelism()
const taskExecutions = 1
workerData
}
)
+
+// FixedClusterPool
+await runPoolifierPoolBenchmark(
+ 'Poolifier FixedClusterPool',
+ buildPoolifierPool(WorkerTypes.cluster, PoolTypes.fixed, poolSize),
+ {
+ taskExecutions,
+ workerData
+ }
+)
+
+// DynamicClusterPool
+await runPoolifierPoolBenchmark(
+ 'Poolifier DynamicClusterPool',
+ buildPoolifierPool(WorkerTypes.cluster, PoolTypes.dynamic, poolSize),
+ {
+ taskExecutions,
+ workerData
+ }
+)
-import { isPrimary } from 'node:cluster'
-import { ClusterWorker } from '../../lib/index.mjs'
-import { executeTaskFunction } from '../benchmarks-utils.mjs'
-import { TaskFunctions } from '../benchmarks-types.mjs'
+const { isPrimary } = require('node:cluster')
+const { ClusterWorker } = require('../../lib')
+const { executeTaskFunction } = require('../benchmarks-utils.js')
+const { TaskFunctions } = require('../benchmarks-types.js')
const taskFunction = data => {
data = data || {}
return res
}
-export default new ClusterWorker(taskFunction)
+module.exports = new ClusterWorker(taskFunction)
import { isMainThread } from 'node:worker_threads'
import { ThreadWorker } from '../../lib/index.mjs'
-import { executeTaskFunction } from '../benchmarks-utils.mjs'
-import { TaskFunctions } from '../benchmarks-types.mjs'
+import { executeTaskFunction } from '../benchmarks-utils.js'
+import { TaskFunctions } from '../benchmarks-types.js'
const taskFunction = data => {
data = data || {}
import Benchmark from 'benchmark'
-import { LIST_FORMATTER, generateRandomInteger } from '../benchmarks-utils.mjs'
+import { LIST_FORMATTER, generateRandomInteger } from '../benchmarks-utils.js'
function generateRandomTasksMap (
numberOfWorkers,
import Benchmark from 'benchmark'
-import { LIST_FORMATTER } from '../benchmarks-utils.mjs'
+import { LIST_FORMATTER } from '../benchmarks-utils.js'
function generateWorkersArray (numberOfWorkers) {
return [...Array(numberOfWorkers).keys()]
"main": "dist/main.js",
"type": "module",
"volta": {
- "node": "20.7.0",
+ "node": "20.8.0",
"pnpm": "8.8.0"
},
"scripts": {
"main": "dist/main.js",
"type": "module",
"volta": {
- "node": "20.7.0",
+ "node": "20.8.0",
"pnpm": "8.8.0"
},
"scripts": {
"main": "dist/main.js",
"type": "module",
"volta": {
- "node": "20.7.0",
+ "node": "20.8.0",
"pnpm": "8.8.0"
},
"scripts": {
"main": "dist/main.js",
"type": "module",
"volta": {
- "node": "20.7.0",
+ "node": "20.8.0",
"pnpm": "8.8.0"
},
"scripts": {
"main": "dist/main.js",
"type": "module",
"volta": {
- "node": "20.7.0",
+ "node": "20.8.0",
"pnpm": "8.8.0"
},
"scripts": {
},
"devDependencies": {
"@rollup/plugin-typescript": "^11.1.4",
- "@types/node": "^20.7.1",
+ "@types/node": "^20.7.2",
"autocannon": "^7.12.0",
"rollup": "^3.29.4",
"rollup-plugin-delete": "^2.0.0",
specifier: ^11.1.4
version: 11.1.4(rollup@3.29.4)(tslib@2.6.2)(typescript@5.2.2)
'@types/node':
- specifier: ^20.7.1
- version: 20.7.1
+ specifier: ^20.7.2
+ version: 20.7.2
autocannon:
specifier: ^7.12.0
version: 7.12.0
resolution: {integrity: sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==}
dependencies:
'@types/minimatch': 5.1.2
- '@types/node': 20.7.1
+ '@types/node': 20.7.2
dev: true
/@types/minimatch@5.1.2:
resolution: {integrity: sha512-K0VQKziLUWkVKiRVrx4a40iPaxTUefQmjtkQofBkYRcoaaL/8rhwDWww9qWbrgicNOgnpIsMxyNIUM4+n6dUIA==}
dev: true
- /@types/node@20.7.1:
- resolution: {integrity: sha512-LT+OIXpp2kj4E2S/p91BMe+VgGX2+lfO+XTpfXhh+bCk2LkQtHZSub8ewFBMGP5ClysPjTDFa4sMI8Q3n4T0wg==}
+ /@types/node@20.7.2:
+ resolution: {integrity: sha512-RcdC3hOBOauLP+r/kRt27NrByYtDjsXyAuSbR87O6xpsvi763WI+5fbSIvYJrXnt9w4RuxhV6eAXfIs7aaf/FQ==}
dev: true
/abort-controller@3.0.0:
"main": "dist/main.js",
"type": "module",
"volta": {
- "node": "20.7.0",
+ "node": "20.8.0",
"pnpm": "8.8.0"
},
"scripts": {
"main": "dist/main.js",
"type": "module",
"volta": {
- "node": "20.7.0",
+ "node": "20.8.0",
"pnpm": "8.8.0"
},
"scripts": {
"main": "dist/main.js",
"type": "module",
"volta": {
- "node": "20.7.0",
+ "node": "20.8.0",
"pnpm": "8.8.0"
},
"scripts": {
"main": "dist/main.js",
"type": "module",
"volta": {
- "node": "20.7.0",
+ "node": "20.8.0",
"pnpm": "8.8.0"
},
"scripts": {
"main": "dist/main.js",
"type": "module",
"volta": {
- "node": "20.7.0",
+ "node": "20.8.0",
"pnpm": "8.8.0"
},
"scripts": {
"main": "dist/main.js",
"type": "module",
"volta": {
- "node": "20.7.0",
+ "node": "20.8.0",
"pnpm": "8.8.0"
},
"scripts": {
"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",
"pnpm": ">=8.6.0"
},
"volta": {
- "node": "20.7.0",
+ "node": "20.8.0",
"pnpm": "8.8.0"
},
"repository": {
"@release-it/keep-a-changelog": "^4.0.0",
"@rollup/plugin-terser": "^0.4.3",
"@rollup/plugin-typescript": "^11.1.4",
- "@types/node": "^20.7.1",
+ "@types/node": "^20.7.2",
"@typescript-eslint/eslint-plugin": "^6.7.3",
"@typescript-eslint/parser": "^6.7.3",
"benchmark": "^2.1.4",
specifier: ^11.1.4
version: 11.1.4(rollup@3.29.4)(typescript@5.2.2)
'@types/node':
- specifier: ^20.7.1
- version: 20.7.1
+ specifier: ^20.7.2
+ version: 20.7.2
'@typescript-eslint/eslint-plugin':
specifier: ^6.7.3
version: 6.7.3(@typescript-eslint/parser@6.7.3)(eslint@8.50.0)(typescript@5.2.2)
lodash.merge: 4.6.2
lodash.uniq: 4.5.0
resolve-from: 5.0.0
- ts-node: 10.9.1(@types/node@20.7.1)(typescript@5.2.2)
+ ts-node: 10.9.1(@types/node@20.7.2)(typescript@5.2.2)
typescript: 5.2.2
transitivePeerDependencies:
- '@swc/core'
'@jest/schemas': 29.6.3
'@types/istanbul-lib-coverage': 2.0.4
'@types/istanbul-reports': 3.0.2
- '@types/node': 20.7.1
- '@types/yargs': 17.0.25
+ '@types/node': 20.7.2
+ '@types/yargs': 17.0.26
chalk: 4.1.2
dev: true
resolution: {integrity: sha512-ZUxbzKl0IfJILTS6t7ip5fQQM/J3TJYubDm3nMbgubNNYS62eXeUpoLUC8/7fJNiFYHTrGPQn7hspDUzIHX3UA==}
dependencies:
'@types/minimatch': 5.1.2
- '@types/node': 20.7.1
+ '@types/node': 20.7.2
dev: true
/@types/http-cache-semantics@4.0.2:
resolution: {integrity: sha512-4tT2UrL5LBqDwoed9wZ6N3umC4Yhz3W3FloMmiiG4JwmUJWpie0c7lcnUNd4gtMKuDEO4wRVS8B6Xa0uMRsMKg==}
dev: true
- /@types/node@20.7.1:
- resolution: {integrity: sha512-LT+OIXpp2kj4E2S/p91BMe+VgGX2+lfO+XTpfXhh+bCk2LkQtHZSub8ewFBMGP5ClysPjTDFa4sMI8Q3n4T0wg==}
+ /@types/node@20.7.2:
+ resolution: {integrity: sha512-RcdC3hOBOauLP+r/kRt27NrByYtDjsXyAuSbR87O6xpsvi763WI+5fbSIvYJrXnt9w4RuxhV6eAXfIs7aaf/FQ==}
dev: true
/@types/normalize-package-data@2.4.2:
resolution: {integrity: sha512-axdPBuLuEJt0c4yI5OZssC19K2Mq1uKdrfZBzuxLvaztgqUtFYZUNw7lETExPYJR9jdEoIg4mb7RQKRQzOkeGQ==}
dev: true
- /@types/yargs@17.0.25:
- resolution: {integrity: sha512-gy7iPgwnzNvxgAEi2bXOHWCVOG6f7xsprVJH4MjlAWeBmJ7vh/Y1kwMtUrs64ztf24zVIRCpr3n/z6gm9QIkgg==}
+ /@types/yargs@17.0.26:
+ resolution: {integrity: sha512-Y3vDy2X6zw/ZCumcwLpdhM5L7jmyGpmBCTYMHDLqT2IKVMYRRLdv6ZakA+wxhra6Z/3bwhNbNl9bDGXaFU+6rw==}
dependencies:
'@types/yargs-parser': 21.0.1
dev: true
dependencies:
'@types/node': 20.5.1
cosmiconfig: 8.3.6(typescript@5.2.2)
- ts-node: 10.9.1(@types/node@20.7.1)(typescript@5.2.2)
+ ts-node: 10.9.1(@types/node@20.7.2)(typescript@5.2.2)
typescript: 5.2.2
dev: true
engines: {node: ^14.15.0 || ^16.10.0 || >=18.0.0}
dependencies:
'@jest/types': 29.6.3
- '@types/node': 20.7.1
+ '@types/node': 20.7.2
chalk: 4.1.2
ci-info: 3.8.0
graceful-fs: 4.2.11
engines: {node: ^12.20.0 || ^14.13.1 || >=16.0.0}
dev: true
- /magic-string@0.30.3:
- resolution: {integrity: sha512-B7xGbll2fG/VjP+SWg4sX3JynwIU0mjoTc6MPpKNuIvftk6u6vqhDnk1R80b8C2GBR6ywqy+1DcKBrevBg+bmw==}
+ /magic-string@0.30.4:
+ resolution: {integrity: sha512-Q/TKtsC5BPm0kGqgBIF9oXAs/xEf2vRKiIB4wCRQTJOQIByZ1d+NnUOotvJOvNpi5RNIgVOMC3pOuaP1ZTDlVg==}
engines: {node: '>=12'}
dependencies:
'@jridgewell/sourcemap-codec': 1.4.15
rollup: ^3.25
typescript: ^4.5 || ^5.0
dependencies:
- magic-string: 0.30.3
+ magic-string: 0.30.4
rollup: 3.29.4
typescript: 5.2.2
optionalDependencies:
typescript: 5.2.2
dev: true
- /ts-node@10.9.1(@types/node@20.7.1)(typescript@5.2.2):
+ /ts-node@10.9.1(@types/node@20.7.2)(typescript@5.2.2):
resolution: {integrity: sha512-NtVysVPkxxrwFGUUxGYhfux8k78pQB3JqYBXlLRZgdGUqTO5wU/UyHop5p70iEbGhB7q5KmiZiU0Y3KlJrScEw==}
hasBin: true
peerDependencies:
'@tsconfig/node12': 1.0.11
'@tsconfig/node14': 1.0.3
'@tsconfig/node16': 1.0.4
- '@types/node': 20.7.1
+ '@types/node': 20.7.2
acorn: 8.10.0
acorn-walk: 8.2.0
arg: 4.1.3
],
plugins: [
typescript({
- tsconfig: './tsconfig.build.json'
+ tsconfig: './tsconfig.build.json',
+ compilerOptions: {
+ sourceMap: sourcemap
+ }
}),
del({
targets: ['./lib/*']
-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', () => {
() =>
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
}
)
- sinon.stub(pool, 'hasBackPressure').returns(true)
+ stub(pool, 'hasBackPressure').returns(true)
expect(pool.emitter.eventNames()).toStrictEqual([])
const promises = new Set()
let poolBackPressure = 0
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 { 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 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'")
-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
let pool
before(() => {
- pool = new FixedThreadPool(max, './tests/worker-files/thread/testWorker.js')
+ pool = new FixedThreadPool(
+ max,
+ './tests/worker-files/thread/testWorker.mjs'
+ )
})
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
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'
)
})
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 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 { 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 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')
})
})
-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 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)
-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', () => {
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
+})
-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
{
"extends": "./tsconfig.json",
- "compilerOptions": {
- "sourceMap": true
- },
"exclude": ["node_modules", "lib", "examples/typescript/**/*.ts"]
}