From: Jérôme Benoit Date: Mon, 26 Jun 2023 22:37:35 +0000 (+0200) Subject: test: message sending from cluster worker X-Git-Tag: v2.6.4~8 X-Git-Url: https://git.piment-noir.org/?a=commitdiff_plain;h=f4fb3543210a05ecc3dbe1bd9c188d2e09d1756d;p=poolifier.git test: message sending from cluster worker Signed-off-by: Jérôme Benoit --- diff --git a/tests/worker/cluster-worker.test.js b/tests/worker/cluster-worker.test.js index f026862d..2d9104bb 100644 --- a/tests/worker/cluster-worker.test.js +++ b/tests/worker/cluster-worker.test.js @@ -2,6 +2,16 @@ const { expect } = require('expect') const { ClusterWorker } = require('../../lib') describe('Cluster worker test suite', () => { + let numberOfMessagesSent = 0 + const send = function () { + ++numberOfMessagesSent + } + class SpyWorker extends ClusterWorker { + getMainWorker () { + return { send } + } + } + it('Verify worker has default maxInactiveTime', () => { const worker = new ClusterWorker(() => {}) expect(worker.opts.maxInactiveTime).toStrictEqual(60000) @@ -12,4 +22,10 @@ describe('Cluster worker test suite', () => { const worker = new ClusterWorker(() => {}) expect(worker.handleError(errorMessage)).toStrictEqual(errorMessage) }) + + it('Verify worker invoke the getMainWorker() and send() methods', () => { + const worker = new SpyWorker(() => {}) + worker.sendToMainWorker({ ok: 1 }) + expect(numberOfMessagesSent).toBe(1) + }) })