From f4fb3543210a05ecc3dbe1bd9c188d2e09d1756d Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A9r=C3=B4me=20Benoit?= Date: Tue, 27 Jun 2023 00:37:35 +0200 Subject: [PATCH] test: message sending from cluster worker MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Signed-off-by: Jérôme Benoit --- tests/worker/cluster-worker.test.js | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) 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) + }) }) -- 2.34.1