Remove unused dependency (#346)
[poolifier.git] / tests / worker / thread-worker.test.js
CommitLineData
fd027a65
S
1const expect = require('expect')
2const { ThreadWorker } = require('../../lib')
3
74a2a194 4let numberOfMessagesPosted = 0
8d3782fa 5const postMessage = function () {
74a2a194 6 numberOfMessagesPosted++
74a2a194
APA
7}
8class SpyWorker extends ThreadWorker {
9 getMainWorker () {
10 return { postMessage: postMessage }
11 }
12}
13
fd027a65
S
14describe('Thread worker test suite', () => {
15 it('Verify worker has default maxInactiveTime', () => {
16 const worker = new ThreadWorker(() => {})
17 expect(worker.maxInactiveTime).toEqual(60_000)
18 })
74a2a194
APA
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 })
fd027a65 25})