"description": "Library on top of node js worker threads that implement various worker pools type",
"main": "lib/index.js",
"scripts": {
- "build": "rollup --config",
- "build:dev": "rollup --config --environment BUILD:development",
- "benchmark": "npm run build && node benchmarks/bench.js",
- "benchmark:debug": "npm run build:dev && node -r source-map-support/register --inspect-brk benchmarks/bench.js",
- "benchmark:debug:vscode": "node -r source-map-support/register benchmarks/bench.js",
- "test": "npm run build && nyc mocha --exit --timeout 20000 'tests/**/*.test.js'",
- "test:debug": "npm run build:dev && mocha -r source-map-support/register --inspect-brk --exit 'tests/**/*.test.js'",
- "test:debug:vscode": "mocha -r source-map-support/register --exit 'tests/**/*.test.js'",
+ "build": "rollup --config --environment BUILD:development",
+ "build:prod": "rollup --config",
+ "benchmark": "npm run build && node -r source-map-support/register benchmarks/bench.js",
+ "benchmark:debug": "npm run build && node -r source-map-support/register --inspect benchmarks/bench.js",
+ "benchmark:prod": "npm run build:prod && node -r source-map-support/register benchmarks/bench.js",
- "test": "npm run build && nyc mocha -r source-map-support/register --exit --timeout 20000 tests/**/*.test.js",
- "test:debug": "npm run build && mocha -r source-map-support/register --inspect --exit --timeout 20000 tests/**/*.test.js",
- "test:prod": "npm run build:prod && nyc mocha -r source-map-support/register --exit --timeout 20000 tests/**/*.test.js",
++ "test": "npm run build && nyc mocha -r source-map-support/register --exit --timeout 20000 'tests/**/*.test.js'",
++ "test:debug": "npm run build && mocha -r source-map-support/register --inspect --exit --timeout 20000 'tests/**/*.test.js'",
++ "test:prod": "npm run build:prod && nyc mocha -r source-map-support/register --exit --timeout 20000 'tests/**/*.test.js'",
"sonar": "sonar-scanner",
"coverage": "nyc report --reporter=lcov --check-coverage --lines 80",
"coverage:html": "nyc report --reporter=html --check-coverage --lines 80",
--- /dev/null
- './tests/worker/cluster/testWorker.js',
+ const expect = require('expect')
+ const { FixedThreadPool } = require('../../../lib/index')
+ const expectedError = new Error('Worker could not be found in tasks map')
+
+ class StubPoolWithTasksMapClear extends FixedThreadPool {
+ removeAllWorker () {
+ this.tasks.clear()
+ }
+ }
+
+ class StubPoolWithIsMainMethod extends FixedThreadPool {
+ isMain () {
+ return false
+ }
+ }
+
+ describe('Abstract pool test suite ', () => {
+ it('Simulate worker not found during increaseWorkersTask', () => {
+ const pool = new StubPoolWithTasksMapClear(
+ 1,
- './tests/worker/cluster/testWorker.js',
++ './tests/worker-files/cluster/testWorker.js',
+ {
+ errorHandler: e => console.error(e)
+ }
+ )
+ // simulate worker not found.
+ pool.removeAllWorker()
+ expect(() => pool.increaseWorkersTask()).toThrowError(expectedError)
+ })
+
+ it('Simulate worker not found during decreaseWorkersTasks', () => {
+ const pool = new StubPoolWithTasksMapClear(
+ 1,
- './tests/worker/cluster/testWorker.js',
++ './tests/worker-files/cluster/testWorker.js',
+ {
+ errorHandler: e => console.error(e)
+ }
+ )
+ // simulate worker not found.
+ pool.removeAllWorker()
+ expect(() => pool.decreaseWorkersTasks()).toThrowError(expectedError)
+ })
+
+ it('Simulate pool creation from a non main thread/process', () => {
+ expect(() => {
+ const pool = new StubPoolWithIsMainMethod(
+ 1,
++ './tests/worker-files/cluster/testWorker.js',
+ {
+ errorHandler: e => console.error(e)
+ }
+ )
+ }).toThrowError()
+ })
+ })
const pool = new DynamicClusterPool(
min,
max,
- './tests/worker/cluster/testWorker.js',
+ './tests/worker-files/cluster/testWorker.js',
{
- errorHandler: e => console.error(e),
- onlineHandler: () => console.log('worker is online')
+ errorHandler: e => console.error(e)
}
)
const maxTasks = 500
const pool = new FixedClusterPool(
numberOfWorkers,
- './tests/worker/cluster/testWorker.js',
+ './tests/worker-files/cluster/testWorker.js',
{
- errorHandler: e => console.error(e),
- onlineHandler: () => console.log('worker is online')
+ errorHandler: e => console.error(e)
}
)
const emptyPool = new FixedClusterPool(
1,
- './tests/worker/cluster/emptyWorker.js'
+ './tests/worker-files/cluster/emptyWorker.js'
+)
+const echoPool = new FixedClusterPool(
+ 1,
+ './tests/worker-files/cluster/echoWorker.js'
)
-const echoPool = new FixedClusterPool(1, './tests/worker/cluster/echoWorker.js')
const errorPool = new FixedClusterPool(
1,
- './tests/worker/cluster/errorWorker.js',
+ './tests/worker-files/cluster/errorWorker.js',
{
- errorHandler: e => console.error(e),
- onlineHandler: () => console.log('worker is online')
+ errorHandler: e => console.error(e)
}
)
const pool = new DynamicThreadPool(
min,
max,
- './tests/worker/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.js',
{
- errorHandler: e => console.error(e),
- onlineHandler: () => console.log('worker is online')
+ errorHandler: e => console.error(e)
}
)
const maxTasks = 400
const pool = new FixedThreadPool(
numberOfThreads,
- './tests/worker/thread/testWorker.js',
+ './tests/worker-files/thread/testWorker.js',
{
- errorHandler: e => console.error(e),
- onlineHandler: () => console.log('worker is online')
+ errorHandler: e => console.error(e)
}
)
-const emptyPool = new FixedThreadPool(1, './tests/worker/thread/emptyWorker.js')
-const echoPool = new FixedThreadPool(1, './tests/worker/thread/echoWorker.js')
+const emptyPool = new FixedThreadPool(
+ 1,
+ './tests/worker-files/thread/emptyWorker.js'
+)
+const echoPool = new FixedThreadPool(
+ 1,
+ './tests/worker-files/thread/echoWorker.js'
+)
const errorPool = new FixedThreadPool(
1,
- './tests/worker/thread/errorWorker.js',
+ './tests/worker-files/thread/errorWorker.js',
{
errorHandler: e => console.error(e),
onlineHandler: () => console.log('worker is online')