From: Shinigami92 Date: Tue, 16 Feb 2021 15:08:46 +0000 (+0100) Subject: Merge branch 'master' into add-worker-test X-Git-Tag: v2.0.0-beta.2~15^2~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=aad2595fd9c26bcb2f0d7a22d06edf56d5b08bdb;p=poolifier.git Merge branch 'master' into add-worker-test --- aad2595fd9c26bcb2f0d7a22d06edf56d5b08bdb diff --cc package.json index fdba3a8b,3831b17b..daf3df0e --- a/package.json +++ b/package.json @@@ -4,14 -4,14 +4,14 @@@ "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", diff --cc tests/pools/abstract/abstract-pool.test.js index 00000000,d5d87058..65d667f1 mode 000000,100644..100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@@ -1,0 -1,55 +1,55 @@@ + 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/cluster/testWorker.js', ++ './tests/worker-files/cluster/testWorker.js', + { + errorHandler: e => console.error(e) + } + ) + }).toThrowError() + }) + }) diff --cc tests/pools/cluster/dynamic.test.js index 36d17d86,b45b7cca..01b72072 --- a/tests/pools/cluster/dynamic.test.js +++ b/tests/pools/cluster/dynamic.test.js @@@ -5,10 -5,9 +5,9 @@@ const max = 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) } ) diff --cc tests/pools/cluster/fixed.test.js index 1cbfadf5,87f7376c..f5300ecc --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@@ -4,26 -4,21 +4,24 @@@ const numberOfWorkers = 1 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) } ) diff --cc tests/pools/thread/dynamic.test.js index 5f6dc8ba,107ca866..4efb0f4b --- a/tests/pools/thread/dynamic.test.js +++ b/tests/pools/thread/dynamic.test.js @@@ -5,10 -5,9 +5,9 @@@ const max = 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) } ) diff --cc tests/pools/thread/fixed.test.js index ff945a70,e160f17c..755ccf4d --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@@ -4,23 -4,16 +4,22 @@@ const numberOfThreads = 1 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')