Pool busy event emitting on all pool types (#241)
[poolifier.git] / tests / worker / abstract-worker.test.js
1 const expect = require('expect')
2 const { ClusterWorker, ThreadWorker } = require('../../lib')
3
4 class StubPoolWithIsMainWorker extends ThreadWorker {
5 constructor (fn, opts) {
6 super(fn, opts)
7 this.mainWorker = false
8 }
9 }
10
11 describe('Abstract worker test suite', () => {
12 it('Verify that fn function is mandatory', () => {
13 expect(() => new ClusterWorker()).toThrowError(
14 new Error('fn parameter is mandatory')
15 )
16 })
17
18 it('Verify that handle Error function is working properly', () => {
19 const error = new Error('My error')
20 const worker = new ThreadWorker(() => {})
21 expect(worker.handleError(error)).toBe(error)
22 })
23
24 it('Verify that get main worker throw error if main worker is not set', () => {
25 expect(() =>
26 new StubPoolWithIsMainWorker(() => {}).getMainWorker()
27 ).toThrowError()
28 })
29 })