Pool busy event emitting on all pool types (#241)
[poolifier.git] / tests / worker / thread-worker.test.js
1 const expect = require('expect')
2 const { ThreadWorker } = require('../../lib')
3
4 let numberOfMessagesPosted = 0
5 const postMessage = function () {
6 numberOfMessagesPosted++
7 }
8 class SpyWorker extends ThreadWorker {
9 getMainWorker () {
10 return { postMessage: postMessage }
11 }
12 }
13
14 describe('Thread worker test suite', () => {
15 it('Verify worker has default maxInactiveTime', () => {
16 const worker = new ThreadWorker(() => {})
17 expect(worker.maxInactiveTime).toEqual(60_000)
18 })
19
20 it('Verify worker invoke the getMainWorker and postMessage methods', () => {
21 const worker = new SpyWorker(() => {})
22 worker.sendToMainWorker({ ok: 1 })
23 expect(numberOfMessagesPosted).toBe(1)
24 })
25 })