1 const expect
= require('expect')
2 const { ClusterWorker
, KillBehaviors
, ThreadWorker
} = require('../../lib')
4 class StubPoolWithIsMainWorker
extends ThreadWorker
{
5 constructor (fn
, opts
) {
7 this.mainWorker
= false
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')
18 it('Verify worker default values', () => {
19 const worker
= new ThreadWorker(() => {})
20 expect(worker
.maxInactiveTime
).toBe(1000 * 60)
21 expect(worker
.killBehavior
).toBe(KillBehaviors
.SOFT
)
22 expect(worker
.async
).toBe(false)
25 it('Verify that worker options are set at worker creation', () => {
26 const worker
= new ClusterWorker(() => {}, {
27 maxInactiveTime
: 6000,
29 killBehavior
: KillBehaviors
.HARD
31 expect(worker
.maxInactiveTime
).toBe(6000)
32 expect(worker
.killBehavior
).toBe(KillBehaviors
.HARD
)
33 expect(worker
.async
).toBe(true)
36 it('Verify that handleError function is working properly', () => {
37 const error
= new Error('My error')
38 const worker
= new ThreadWorker(() => {})
39 expect(worker
.handleError(error
)).toBe(error
)
42 it('Verify that get main worker throw error if main worker is not set', () => {
44 new StubPoolWithIsMainWorker(() => {}).getMainWorker()
45 ).toThrowError(new Error('Main worker was not set'))