From: Alessandro Pio Ardizio Date: Mon, 22 Feb 2021 10:28:22 +0000 (+0100) Subject: Coverage increased (#217) X-Git-Tag: v2.0.0-beta.7~1 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=74a2a19445618440f22537123650c01d065ae358;p=poolifier.git Coverage increased (#217) --- diff --git a/tests/worker-files/cluster/echoWorker.js b/tests/worker-files/cluster/echoWorker.js index 9bcae281..685d971e 100644 --- a/tests/worker-files/cluster/echoWorker.js +++ b/tests/worker-files/cluster/echoWorker.js @@ -5,6 +5,4 @@ function echo (data) { return data } -module.exports = new ClusterWorker(echo, { - killBehavior: KillBehaviors.HARD -}) +module.exports = new ClusterWorker(echo) diff --git a/tests/worker/thread-worker.test.js b/tests/worker/thread-worker.test.js index 240534a7..dfe49655 100644 --- a/tests/worker/thread-worker.test.js +++ b/tests/worker/thread-worker.test.js @@ -1,9 +1,26 @@ const expect = require('expect') const { ThreadWorker } = require('../../lib') +let numberOfMessagesPosted = 0 +const postMessage = function (message) { + numberOfMessagesPosted++ + console.log(message) +} +class SpyWorker extends ThreadWorker { + getMainWorker () { + return { postMessage: postMessage } + } +} + describe('Thread worker test suite', () => { it('Verify worker has default maxInactiveTime', () => { const worker = new ThreadWorker(() => {}) expect(worker.maxInactiveTime).toEqual(60_000) }) + + it('Verify worker invoke the getMainWorker and postMessage methods', () => { + const worker = new SpyWorker(() => {}) + worker.sendToMainWorker({ ok: 1 }) + expect(numberOfMessagesPosted).toBe(1) + }) })