Commit | Line | Data |
---|---|---|
c510fea7 | 1 | const expect = require('expect') |
8620fb25 | 2 | const { ClusterWorker, KillBehaviors, ThreadWorker } = require('../../lib') |
7fc5cce6 APA |
3 | |
4 | class StubPoolWithIsMainWorker extends ThreadWorker { | |
5 | constructor (fn, opts) { | |
6 | super(fn, opts) | |
7 | this.mainWorker = false | |
8 | } | |
9 | } | |
c510fea7 APA |
10 | |
11 | describe('Abstract worker test suite', () => { | |
12 | it('Verify that fn function is mandatory', () => { | |
8d3782fa JB |
13 | expect(() => new ClusterWorker()).toThrowError( |
14 | new Error('fn parameter is mandatory') | |
15 | ) | |
c510fea7 | 16 | }) |
7fc5cce6 | 17 | |
8620fb25 JB |
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) | |
23 | }) | |
24 | ||
25 | it('Verify that worker options are set at worker creation', () => { | |
26 | const worker = new ClusterWorker(() => {}, { | |
27 | maxInactiveTime: 6000, | |
28 | async: true, | |
29 | killBehavior: KillBehaviors.HARD | |
30 | }) | |
31 | expect(worker.maxInactiveTime).toBe(6000) | |
32 | expect(worker.killBehavior).toBe(KillBehaviors.HARD) | |
33 | expect(worker.async).toBe(true) | |
34 | }) | |
35 | ||
292ad316 | 36 | it('Verify that handleError function is working properly', () => { |
7fc5cce6 APA |
37 | const error = new Error('My error') |
38 | const worker = new ThreadWorker(() => {}) | |
39 | expect(worker.handleError(error)).toBe(error) | |
40 | }) | |
41 | ||
42 | it('Verify that get main worker throw error if main worker is not set', () => { | |
43 | expect(() => | |
44 | new StubPoolWithIsMainWorker(() => {}).getMainWorker() | |
292ad316 | 45 | ).toThrowError(new Error('Main worker was not set')) |
7fc5cce6 | 46 | }) |
c510fea7 | 47 | }) |