Commit | Line | Data |
---|---|---|
3ec964d6 | 1 | const expect = require('expect') |
2 | const { FixedThreadPool } = require('../../../lib/index') | |
3 | const expectedError = new Error('Worker could not be found in tasks map') | |
4 | ||
5 | class StubPoolWithTasksMapClear extends FixedThreadPool { | |
6 | removeAllWorker () { | |
7 | this.tasks.clear() | |
8 | } | |
9 | } | |
10 | ||
11 | class StubPoolWithIsMainMethod extends FixedThreadPool { | |
12 | isMain () { | |
13 | return false | |
14 | } | |
15 | } | |
16 | ||
a35560ba | 17 | describe('Abstract pool test suite', () => { |
3ec964d6 | 18 | it('Simulate worker not found during increaseWorkersTask', () => { |
19 | const pool = new StubPoolWithTasksMapClear( | |
20 | 1, | |
aad2595f | 21 | './tests/worker-files/cluster/testWorker.js', |
3ec964d6 | 22 | { |
23 | errorHandler: e => console.error(e) | |
24 | } | |
25 | ) | |
0e2503fc | 26 | // Simulate worker not found. |
3ec964d6 | 27 | pool.removeAllWorker() |
28 | expect(() => pool.increaseWorkersTask()).toThrowError(expectedError) | |
29 | }) | |
30 | ||
31 | it('Simulate worker not found during decreaseWorkersTasks', () => { | |
32 | const pool = new StubPoolWithTasksMapClear( | |
33 | 1, | |
aad2595f | 34 | './tests/worker-files/cluster/testWorker.js', |
3ec964d6 | 35 | { |
36 | errorHandler: e => console.error(e) | |
37 | } | |
38 | ) | |
0e2503fc | 39 | // Simulate worker not found. |
3ec964d6 | 40 | pool.removeAllWorker() |
41 | expect(() => pool.decreaseWorkersTasks()).toThrowError(expectedError) | |
42 | }) | |
43 | ||
44 | it('Simulate pool creation from a non main thread/process', () => { | |
45 | expect(() => { | |
46 | const pool = new StubPoolWithIsMainMethod( | |
47 | 1, | |
aad2595f | 48 | './tests/worker-files/cluster/testWorker.js', |
3ec964d6 | 49 | { |
50 | errorHandler: e => console.error(e) | |
51 | } | |
52 | ) | |
53 | }).toThrowError() | |
54 | }) | |
c510fea7 APA |
55 | |
56 | it('Verify that filePath is checked', () => { | |
57 | expect(() => { | |
58 | const pool = new StubPoolWithIsMainMethod(1).toThrowError() | |
59 | }) | |
60 | expect(() => { | |
61 | const pool = new StubPoolWithIsMainMethod(1, '').toThrowError() | |
62 | }) | |
63 | }) | |
3ec964d6 | 64 | }) |