From: Alessandro Pio Ardizio Date: Tue, 16 Feb 2021 16:39:47 +0000 (+0100) Subject: Merge pull request #153 from pioardi/add-worker-test X-Git-Tag: v2.0.0-beta.2~15 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=e901162fa610e2af305aac504549580b2de48cab;hp=15eacd5dc058773d3422ee2dd2453d89bd7e60c3;p=poolifier.git Merge pull request #153 from pioardi/add-worker-test Add tests for workers --- diff --git a/package.json b/package.json index 3831b17b..daf3df0e 100644 --- a/package.json +++ b/package.json @@ -9,9 +9,9 @@ "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 --git a/tests/pools/abstract/abstract-pool.test.js b/tests/pools/abstract/abstract-pool.test.js index d5d87058..65d667f1 100644 --- a/tests/pools/abstract/abstract-pool.test.js +++ b/tests/pools/abstract/abstract-pool.test.js @@ -18,7 +18,7 @@ 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) } @@ -31,7 +31,7 @@ describe('Abstract pool test suite ', () => { 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) } @@ -45,7 +45,7 @@ describe('Abstract pool test suite ', () => { expect(() => { const pool = new StubPoolWithIsMainMethod( 1, - './tests/worker/cluster/testWorker.js', + './tests/worker-files/cluster/testWorker.js', { errorHandler: e => console.error(e) } diff --git a/tests/pools/cluster/dynamic.test.js b/tests/pools/cluster/dynamic.test.js index b45b7cca..01b72072 100644 --- a/tests/pools/cluster/dynamic.test.js +++ b/tests/pools/cluster/dynamic.test.js @@ -5,7 +5,7 @@ const max = 3 const pool = new DynamicClusterPool( min, max, - './tests/worker/cluster/testWorker.js', + './tests/worker-files/cluster/testWorker.js', { errorHandler: e => console.error(e) } @@ -81,7 +81,7 @@ describe('Dynamic cluster pool test suite ', () => { const pool1 = new DynamicClusterPool( 1, 1, - './tests/worker/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.js' ) const res = await pool1.execute({ test: 'test' }) expect(res).toBeFalsy() diff --git a/tests/pools/cluster/fixed.test.js b/tests/pools/cluster/fixed.test.js index 87f7376c..f5300ecc 100644 --- a/tests/pools/cluster/fixed.test.js +++ b/tests/pools/cluster/fixed.test.js @@ -4,19 +4,22 @@ const numberOfWorkers = 10 const maxTasks = 500 const pool = new FixedClusterPool( numberOfWorkers, - './tests/worker/cluster/testWorker.js', + './tests/worker-files/cluster/testWorker.js', { 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) } @@ -24,14 +27,14 @@ const errorPool = new FixedClusterPool( const asyncErrorPool = new FixedClusterPool( 1, - './tests/worker/cluster/asyncErrorWorker.js', + './tests/worker-files/cluster/asyncErrorWorker.js', { onlineHandler: () => console.log('worker is online') } ) const asyncPool = new FixedClusterPool( 1, - './tests/worker/cluster/asyncWorker.js', + './tests/worker-files/cluster/asyncWorker.js', { maxTasks: maxTasks } @@ -138,7 +141,7 @@ describe('Fixed cluster pool test suite ', () => { it('Should work even without opts in input', async () => { const pool1 = new FixedClusterPool( 1, - './tests/worker/cluster/testWorker.js' + './tests/worker-files/cluster/testWorker.js' ) const res = await pool1.execute({ test: 'test' }) expect(res).toBeFalsy() diff --git a/tests/pools/thread/dynamic.test.js b/tests/pools/thread/dynamic.test.js index 107ca866..4efb0f4b 100644 --- a/tests/pools/thread/dynamic.test.js +++ b/tests/pools/thread/dynamic.test.js @@ -5,7 +5,7 @@ const max = 3 const pool = new DynamicThreadPool( min, max, - './tests/worker/thread/testWorker.js', + './tests/worker-files/thread/testWorker.js', { errorHandler: e => console.error(e) } @@ -80,7 +80,7 @@ describe('Dynamic thread pool test suite ', () => { const pool1 = new DynamicThreadPool( 1, 1, - './tests/worker/thread/testWorker.js' + './tests/worker-files/thread/testWorker.js' ) const res = await pool1.execute({ test: 'test' }) expect(res).toBeFalsy() diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index e160f17c..755ccf4d 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -4,16 +4,22 @@ const numberOfThreads = 10 const maxTasks = 400 const pool = new FixedThreadPool( numberOfThreads, - './tests/worker/thread/testWorker.js', + './tests/worker-files/thread/testWorker.js', { 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') @@ -21,7 +27,7 @@ const errorPool = new FixedThreadPool( ) const asyncPool = new FixedThreadPool( 1, - './tests/worker/thread/asyncWorker.js', + './tests/worker-files/thread/asyncWorker.js', { maxTasks: maxTasks } ) @@ -110,7 +116,10 @@ describe('Fixed thread pool test suite ', () => { }) it('Should work even without opts in input', async () => { - const pool1 = new FixedThreadPool(1, './tests/worker/thread/testWorker.js') + const pool1 = new FixedThreadPool( + 1, + './tests/worker-files/thread/testWorker.js' + ) const res = await pool1.execute({ test: 'test' }) expect(res).toBeFalsy() }) diff --git a/tests/worker/cluster/asyncErrorWorker.js b/tests/worker-files/cluster/asyncErrorWorker.js similarity index 100% rename from tests/worker/cluster/asyncErrorWorker.js rename to tests/worker-files/cluster/asyncErrorWorker.js diff --git a/tests/worker/cluster/asyncWorker.js b/tests/worker-files/cluster/asyncWorker.js similarity index 100% rename from tests/worker/cluster/asyncWorker.js rename to tests/worker-files/cluster/asyncWorker.js diff --git a/tests/worker/cluster/echoWorker.js b/tests/worker-files/cluster/echoWorker.js similarity index 100% rename from tests/worker/cluster/echoWorker.js rename to tests/worker-files/cluster/echoWorker.js diff --git a/tests/worker/cluster/emptyWorker.js b/tests/worker-files/cluster/emptyWorker.js similarity index 100% rename from tests/worker/cluster/emptyWorker.js rename to tests/worker-files/cluster/emptyWorker.js diff --git a/tests/worker/cluster/errorWorker.js b/tests/worker-files/cluster/errorWorker.js similarity index 100% rename from tests/worker/cluster/errorWorker.js rename to tests/worker-files/cluster/errorWorker.js diff --git a/tests/worker/cluster/testWorker.js b/tests/worker-files/cluster/testWorker.js similarity index 100% rename from tests/worker/cluster/testWorker.js rename to tests/worker-files/cluster/testWorker.js diff --git a/tests/worker/thread/asyncWorker.js b/tests/worker-files/thread/asyncWorker.js similarity index 100% rename from tests/worker/thread/asyncWorker.js rename to tests/worker-files/thread/asyncWorker.js diff --git a/tests/worker/thread/echoWorker.js b/tests/worker-files/thread/echoWorker.js similarity index 100% rename from tests/worker/thread/echoWorker.js rename to tests/worker-files/thread/echoWorker.js diff --git a/tests/worker/thread/emptyWorker.js b/tests/worker-files/thread/emptyWorker.js similarity index 100% rename from tests/worker/thread/emptyWorker.js rename to tests/worker-files/thread/emptyWorker.js diff --git a/tests/worker/thread/errorWorker.js b/tests/worker-files/thread/errorWorker.js similarity index 100% rename from tests/worker/thread/errorWorker.js rename to tests/worker-files/thread/errorWorker.js diff --git a/tests/worker/thread/testWorker.js b/tests/worker-files/thread/testWorker.js similarity index 100% rename from tests/worker/thread/testWorker.js rename to tests/worker-files/thread/testWorker.js diff --git a/tests/worker/cluster-worker.test.js b/tests/worker/cluster-worker.test.js new file mode 100644 index 00000000..fc2d3442 --- /dev/null +++ b/tests/worker/cluster-worker.test.js @@ -0,0 +1,10 @@ +const expect = require('expect') +const { ClusterWorker } = require('../../lib') + +describe('Cluster worker test suite', () => { + // Skipped because ClusterWorker would be in main instead of non-main worker + it.skip('Verify worker has default maxInactiveTime', () => { + const worker = new ClusterWorker(() => {}) + expect(worker.maxInactiveTime).toEqual(60_000) + }) +}) diff --git a/tests/worker/thread-worker.test.js b/tests/worker/thread-worker.test.js new file mode 100644 index 00000000..240534a7 --- /dev/null +++ b/tests/worker/thread-worker.test.js @@ -0,0 +1,9 @@ +const expect = require('expect') +const { ThreadWorker } = require('../../lib') + +describe('Thread worker test suite', () => { + it('Verify worker has default maxInactiveTime', () => { + const worker = new ThreadWorker(() => {}) + expect(worker.maxInactiveTime).toEqual(60_000) + }) +})