From 7fc5cce6ed95bfc01cb6199893cf104c3a3c0f0a Mon Sep 17 00:00:00 2001 From: Alessandro Pio Ardizio Date: Tue, 23 Feb 2021 12:45:38 +0100 Subject: [PATCH] Coverage increased (#226) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit * Coverage increased * Few changes Co-authored-by: Jérôme Benoit --- tests/pools/thread/fixed.test.js | 3 ++- tests/worker/abstract-worker.test.js | 21 ++++++++++++++++++++- tests/worker/cluster-worker.test.js | 6 ++++++ 3 files changed, 28 insertions(+), 2 deletions(-) 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) + }) }) -- 2.34.1