From: Alessandro Pio Ardizio Date: Tue, 23 Feb 2021 11:45:38 +0000 (+0100) Subject: Coverage increased (#226) X-Git-Tag: v2.0.0~18 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=7fc5cce6ed95bfc01cb6199893cf104c3a3c0f0a;p=poolifier.git Coverage increased (#226) * Coverage increased * Few changes Co-authored-by: Jérôme Benoit --- diff --git a/tests/pools/thread/fixed.test.js b/tests/pools/thread/fixed.test.js index cc60a9b5..b70d4c62 100644 --- a/tests/pools/thread/fixed.test.js +++ b/tests/pools/thread/fixed.test.js @@ -11,7 +11,8 @@ const pool = new FixedThreadPool( ) const emptyPool = new FixedThreadPool( 1, - './tests/worker-files/thread/emptyWorker.js' + './tests/worker-files/thread/emptyWorker.js', + { exitHandler: () => console.log('WORKER EXITED') } ) const echoPool = new FixedThreadPool( 1, diff --git a/tests/worker/abstract-worker.test.js b/tests/worker/abstract-worker.test.js index 0c9b665e..1d0c03d9 100644 --- a/tests/worker/abstract-worker.test.js +++ b/tests/worker/abstract-worker.test.js @@ -1,5 +1,12 @@ const expect = require('expect') -const { ClusterWorker } = require('../../lib') +const { ClusterWorker, ThreadWorker } = require('../../lib') + +class StubPoolWithIsMainWorker extends ThreadWorker { + constructor (fn, opts) { + super(fn, opts) + this.mainWorker = false + } +} describe('Abstract worker test suite', () => { it('Verify that fn function is mandatory', () => { @@ -7,4 +14,16 @@ describe('Abstract worker test suite', () => { new Error('fn parameter is mandatory') ) }) + + it('Verify that handle Error function is working properly', () => { + const error = new Error('My error') + const worker = new ThreadWorker(() => {}) + expect(worker.handleError(error)).toBe(error) + }) + + it('Verify that get main worker throw error if main worker is not set', () => { + expect(() => + new StubPoolWithIsMainWorker(() => {}).getMainWorker() + ).toThrowError() + }) }) diff --git a/tests/worker/cluster-worker.test.js b/tests/worker/cluster-worker.test.js index 5dec6076..196564a4 100644 --- a/tests/worker/cluster-worker.test.js +++ b/tests/worker/cluster-worker.test.js @@ -6,4 +6,10 @@ describe('Cluster worker test suite', () => { const worker = new ClusterWorker(() => {}) expect(worker.maxInactiveTime).toEqual(60_000) }) + + it('Verify that handleError function works properly', () => { + const errorMessage = 'Error as a string' + const worker = new ClusterWorker(() => {}) + expect(worker.handleError(errorMessage)).toBe(errorMessage) + }) })