chore: v2.6.9
[poolifier.git] / tests / worker / cluster-worker.test.js
index 5be57a0ddfabb9ddfbb76f0556f823b25ac0ed50..2d9104bb3c185b52bf05f8ec114d8d7008745583 100644 (file)
@@ -1,15 +1,31 @@
-const expect = require('expect')
+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).toEqual(60000)
+    expect(worker.opts.maxInactiveTime).toStrictEqual(60000)
   })
 
-  it('Verify that handleError function works properly', () => {
+  it('Verify that handleError() method works properly', () => {
     const errorMessage = 'Error as a string'
     const worker = new ClusterWorker(() => {})
-    expect(worker.handleError(errorMessage)).toBe(errorMessage)
+    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)
   })
 })