Commit | Line | Data |
---|---|---|
a61a0724 | 1 | const { expect } = require('expect') |
b1aae695 | 2 | const sinon = require('sinon') |
e843b904 | 3 | const { |
70a4f5ea | 4 | DynamicClusterPool, |
9e619829 | 5 | DynamicThreadPool, |
aee46736 | 6 | FixedClusterPool, |
e843b904 | 7 | FixedThreadPool, |
aee46736 | 8 | PoolEvents, |
184855e6 | 9 | PoolTypes, |
3d6dd312 | 10 | WorkerChoiceStrategies, |
184855e6 | 11 | WorkerTypes |
cdace0e5 | 12 | } = require('../../../lib') |
78099a15 | 13 | const { CircularArray } = require('../../../lib/circular-array') |
29ee7e9a | 14 | const { Queue } = require('../../../lib/queue') |
23ccf9d7 | 15 | const { version } = require('../../../package.json') |
2431bdb4 | 16 | const { waitPoolEvents } = require('../../test-utils') |
e1ffb94f JB |
17 | |
18 | describe('Abstract pool test suite', () => { | |
fc027381 | 19 | const numberOfWorkers = 2 |
a8884ffd | 20 | class StubPoolWithIsMain extends FixedThreadPool { |
e1ffb94f JB |
21 | isMain () { |
22 | return false | |
23 | } | |
3ec964d6 | 24 | } |
3ec964d6 | 25 | |
3ec964d6 | 26 | it('Simulate pool creation from a non main thread/process', () => { |
8d3782fa JB |
27 | expect( |
28 | () => | |
a8884ffd | 29 | new StubPoolWithIsMain( |
7c0ba920 | 30 | numberOfWorkers, |
8d3782fa JB |
31 | './tests/worker-files/thread/testWorker.js', |
32 | { | |
8ebe6c30 | 33 | errorHandler: (e) => console.error(e) |
8d3782fa JB |
34 | } |
35 | ) | |
04f45163 | 36 | ).toThrowError( |
e695d66f JB |
37 | new Error( |
38 | 'Cannot start a pool from a worker with the same type as the pool' | |
39 | ) | |
04f45163 | 40 | ) |
3ec964d6 | 41 | }) |
c510fea7 APA |
42 | |
43 | it('Verify that filePath is checked', () => { | |
292ad316 JB |
44 | const expectedError = new Error( |
45 | 'Please specify a file with a worker implementation' | |
46 | ) | |
7c0ba920 | 47 | expect(() => new FixedThreadPool(numberOfWorkers)).toThrowError( |
292ad316 | 48 | expectedError |
8d3782fa | 49 | ) |
7c0ba920 | 50 | expect(() => new FixedThreadPool(numberOfWorkers, '')).toThrowError( |
292ad316 | 51 | expectedError |
8d3782fa | 52 | ) |
3d6dd312 JB |
53 | expect(() => new FixedThreadPool(numberOfWorkers, 0)).toThrowError( |
54 | expectedError | |
55 | ) | |
56 | expect(() => new FixedThreadPool(numberOfWorkers, true)).toThrowError( | |
57 | expectedError | |
58 | ) | |
59 | expect( | |
60 | () => new FixedThreadPool(numberOfWorkers, './dummyWorker.ts') | |
61 | ).toThrowError(new Error("Cannot find the worker file './dummyWorker.ts'")) | |
8d3782fa JB |
62 | }) |
63 | ||
64 | it('Verify that numberOfWorkers is checked', () => { | |
65 | expect(() => new FixedThreadPool()).toThrowError( | |
e695d66f JB |
66 | new Error( |
67 | 'Cannot instantiate a pool without specifying the number of workers' | |
68 | ) | |
8d3782fa JB |
69 | ) |
70 | }) | |
71 | ||
72 | it('Verify that a negative number of workers is checked', () => { | |
73 | expect( | |
74 | () => | |
75 | new FixedClusterPool(-1, './tests/worker-files/cluster/testWorker.js') | |
76 | ).toThrowError( | |
473c717a JB |
77 | new RangeError( |
78 | 'Cannot instantiate a pool with a negative number of workers' | |
79 | ) | |
8d3782fa JB |
80 | ) |
81 | }) | |
82 | ||
83 | it('Verify that a non integer number of workers is checked', () => { | |
84 | expect( | |
85 | () => | |
86 | new FixedThreadPool(0.25, './tests/worker-files/thread/testWorker.js') | |
87 | ).toThrowError( | |
473c717a | 88 | new TypeError( |
0d80593b | 89 | 'Cannot instantiate a pool with a non safe integer number of workers' |
8d3782fa JB |
90 | ) |
91 | ) | |
c510fea7 | 92 | }) |
7c0ba920 | 93 | |
216541b6 | 94 | it('Verify that dynamic pool sizing is checked', () => { |
a5ed75b7 JB |
95 | expect( |
96 | () => | |
97 | new DynamicClusterPool( | |
98 | 1, | |
99 | undefined, | |
100 | './tests/worker-files/cluster/testWorker.js' | |
101 | ) | |
102 | ).toThrowError( | |
103 | new TypeError( | |
104 | 'Cannot instantiate a dynamic pool without specifying the maximum pool size' | |
105 | ) | |
106 | ) | |
2761efb4 JB |
107 | expect( |
108 | () => | |
109 | new DynamicThreadPool( | |
110 | 0.5, | |
111 | 1, | |
112 | './tests/worker-files/thread/testWorker.js' | |
113 | ) | |
114 | ).toThrowError( | |
115 | new TypeError( | |
116 | 'Cannot instantiate a pool with a non safe integer number of workers' | |
117 | ) | |
118 | ) | |
119 | expect( | |
120 | () => | |
121 | new DynamicClusterPool( | |
122 | 0, | |
123 | 0.5, | |
a5ed75b7 | 124 | './tests/worker-files/cluster/testWorker.js' |
2761efb4 JB |
125 | ) |
126 | ).toThrowError( | |
127 | new TypeError( | |
128 | 'Cannot instantiate a dynamic pool with a non safe integer maximum pool size' | |
129 | ) | |
130 | ) | |
2431bdb4 JB |
131 | expect( |
132 | () => | |
133 | new DynamicThreadPool(2, 1, './tests/worker-files/thread/testWorker.js') | |
134 | ).toThrowError( | |
135 | new RangeError( | |
136 | 'Cannot instantiate a dynamic pool with a maximum pool size inferior to the minimum pool size' | |
137 | ) | |
138 | ) | |
139 | expect( | |
140 | () => | |
2761efb4 JB |
141 | new DynamicClusterPool( |
142 | 1, | |
143 | 1, | |
a5ed75b7 | 144 | './tests/worker-files/cluster/testWorker.js' |
2761efb4 | 145 | ) |
2431bdb4 JB |
146 | ).toThrowError( |
147 | new RangeError( | |
148 | 'Cannot instantiate a dynamic pool with a minimum pool size equal to the maximum pool size. Use a fixed pool instead' | |
149 | ) | |
150 | ) | |
21f710aa JB |
151 | expect( |
152 | () => | |
153 | new DynamicThreadPool(0, 0, './tests/worker-files/thread/testWorker.js') | |
154 | ).toThrowError( | |
155 | new RangeError( | |
d640b48b | 156 | 'Cannot instantiate a dynamic pool with a maximum pool size equal to zero' |
21f710aa JB |
157 | ) |
158 | ) | |
2431bdb4 JB |
159 | }) |
160 | ||
fd7ebd49 | 161 | it('Verify that pool options are checked', async () => { |
7c0ba920 JB |
162 | let pool = new FixedThreadPool( |
163 | numberOfWorkers, | |
164 | './tests/worker-files/thread/testWorker.js' | |
165 | ) | |
7c0ba920 | 166 | expect(pool.emitter).toBeDefined() |
1f68cede JB |
167 | expect(pool.opts.enableEvents).toBe(true) |
168 | expect(pool.opts.restartWorkerOnError).toBe(true) | |
ff733df7 | 169 | expect(pool.opts.enableTasksQueue).toBe(false) |
d4aeae5a | 170 | expect(pool.opts.tasksQueueOptions).toBeUndefined() |
e843b904 JB |
171 | expect(pool.opts.workerChoiceStrategy).toBe( |
172 | WorkerChoiceStrategies.ROUND_ROBIN | |
173 | ) | |
da309861 | 174 | expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({ |
8990357d JB |
175 | choiceRetries: 6, |
176 | runTime: { median: false }, | |
177 | waitTime: { median: false }, | |
178 | elu: { median: false } | |
179 | }) | |
180 | expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({ | |
181 | choiceRetries: 6, | |
932fc8be | 182 | runTime: { median: false }, |
5df69fab JB |
183 | waitTime: { median: false }, |
184 | elu: { median: false } | |
da309861 | 185 | }) |
35cf1c03 JB |
186 | expect(pool.opts.messageHandler).toBeUndefined() |
187 | expect(pool.opts.errorHandler).toBeUndefined() | |
188 | expect(pool.opts.onlineHandler).toBeUndefined() | |
189 | expect(pool.opts.exitHandler).toBeUndefined() | |
fd7ebd49 | 190 | await pool.destroy() |
73bfd59d | 191 | const testHandler = () => console.info('test handler executed') |
7c0ba920 JB |
192 | pool = new FixedThreadPool( |
193 | numberOfWorkers, | |
194 | './tests/worker-files/thread/testWorker.js', | |
195 | { | |
e4543b14 | 196 | workerChoiceStrategy: WorkerChoiceStrategies.LEAST_USED, |
49be33fe | 197 | workerChoiceStrategyOptions: { |
932fc8be | 198 | runTime: { median: true }, |
fc027381 | 199 | weights: { 0: 300, 1: 200 } |
49be33fe | 200 | }, |
35cf1c03 | 201 | enableEvents: false, |
1f68cede | 202 | restartWorkerOnError: false, |
ff733df7 | 203 | enableTasksQueue: true, |
d4aeae5a | 204 | tasksQueueOptions: { concurrency: 2 }, |
35cf1c03 JB |
205 | messageHandler: testHandler, |
206 | errorHandler: testHandler, | |
207 | onlineHandler: testHandler, | |
208 | exitHandler: testHandler | |
7c0ba920 JB |
209 | } |
210 | ) | |
7c0ba920 | 211 | expect(pool.emitter).toBeUndefined() |
1f68cede JB |
212 | expect(pool.opts.enableEvents).toBe(false) |
213 | expect(pool.opts.restartWorkerOnError).toBe(false) | |
ff733df7 | 214 | expect(pool.opts.enableTasksQueue).toBe(true) |
d4aeae5a | 215 | expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 2 }) |
e843b904 | 216 | expect(pool.opts.workerChoiceStrategy).toBe( |
e4543b14 | 217 | WorkerChoiceStrategies.LEAST_USED |
e843b904 | 218 | ) |
da309861 | 219 | expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({ |
8990357d | 220 | choiceRetries: 6, |
932fc8be | 221 | runTime: { median: true }, |
8990357d JB |
222 | waitTime: { median: false }, |
223 | elu: { median: false }, | |
224 | weights: { 0: 300, 1: 200 } | |
225 | }) | |
226 | expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({ | |
227 | choiceRetries: 6, | |
228 | runTime: { median: true }, | |
229 | waitTime: { median: false }, | |
230 | elu: { median: false }, | |
fc027381 | 231 | weights: { 0: 300, 1: 200 } |
da309861 | 232 | }) |
35cf1c03 JB |
233 | expect(pool.opts.messageHandler).toStrictEqual(testHandler) |
234 | expect(pool.opts.errorHandler).toStrictEqual(testHandler) | |
235 | expect(pool.opts.onlineHandler).toStrictEqual(testHandler) | |
236 | expect(pool.opts.exitHandler).toStrictEqual(testHandler) | |
fd7ebd49 | 237 | await pool.destroy() |
7c0ba920 JB |
238 | }) |
239 | ||
a20f0ba5 | 240 | it('Verify that pool options are validated', async () => { |
d4aeae5a JB |
241 | expect( |
242 | () => | |
243 | new FixedThreadPool( | |
244 | numberOfWorkers, | |
245 | './tests/worker-files/thread/testWorker.js', | |
246 | { | |
f0d7f803 | 247 | workerChoiceStrategy: 'invalidStrategy' |
d4aeae5a JB |
248 | } |
249 | ) | |
8735b4e5 JB |
250 | ).toThrowError( |
251 | new Error("Invalid worker choice strategy 'invalidStrategy'") | |
252 | ) | |
49be33fe JB |
253 | expect( |
254 | () => | |
255 | new FixedThreadPool( | |
256 | numberOfWorkers, | |
257 | './tests/worker-files/thread/testWorker.js', | |
258 | { | |
259 | workerChoiceStrategyOptions: { weights: {} } | |
260 | } | |
261 | ) | |
262 | ).toThrowError( | |
8735b4e5 JB |
263 | new Error( |
264 | 'Invalid worker choice strategy options: must have a weight for each worker node' | |
265 | ) | |
49be33fe | 266 | ) |
f0d7f803 JB |
267 | expect( |
268 | () => | |
269 | new FixedThreadPool( | |
270 | numberOfWorkers, | |
271 | './tests/worker-files/thread/testWorker.js', | |
272 | { | |
273 | workerChoiceStrategyOptions: { measurement: 'invalidMeasurement' } | |
274 | } | |
275 | ) | |
276 | ).toThrowError( | |
8735b4e5 JB |
277 | new Error( |
278 | "Invalid worker choice strategy options: invalid measurement 'invalidMeasurement'" | |
279 | ) | |
f0d7f803 JB |
280 | ) |
281 | expect( | |
282 | () => | |
283 | new FixedThreadPool( | |
284 | numberOfWorkers, | |
285 | './tests/worker-files/thread/testWorker.js', | |
286 | { | |
287 | enableTasksQueue: true, | |
288 | tasksQueueOptions: { concurrency: 0 } | |
289 | } | |
290 | ) | |
8735b4e5 | 291 | ).toThrowError( |
e695d66f | 292 | new RangeError( |
8735b4e5 JB |
293 | 'Invalid worker tasks concurrency: 0 is a negative integer or zero' |
294 | ) | |
295 | ) | |
f0d7f803 JB |
296 | expect( |
297 | () => | |
298 | new FixedThreadPool( | |
299 | numberOfWorkers, | |
300 | './tests/worker-files/thread/testWorker.js', | |
301 | { | |
302 | enableTasksQueue: true, | |
303 | tasksQueueOptions: 'invalidTasksQueueOptions' | |
304 | } | |
305 | ) | |
8735b4e5 JB |
306 | ).toThrowError( |
307 | new TypeError('Invalid tasks queue options: must be a plain object') | |
308 | ) | |
f0d7f803 JB |
309 | expect( |
310 | () => | |
311 | new FixedThreadPool( | |
312 | numberOfWorkers, | |
313 | './tests/worker-files/thread/testWorker.js', | |
314 | { | |
315 | enableTasksQueue: true, | |
316 | tasksQueueOptions: { concurrency: 0.2 } | |
317 | } | |
318 | ) | |
8735b4e5 JB |
319 | ).toThrowError( |
320 | new TypeError('Invalid worker tasks concurrency: must be an integer') | |
321 | ) | |
d4aeae5a JB |
322 | }) |
323 | ||
2431bdb4 | 324 | it('Verify that pool worker choice strategy options can be set', async () => { |
a20f0ba5 JB |
325 | const pool = new FixedThreadPool( |
326 | numberOfWorkers, | |
327 | './tests/worker-files/thread/testWorker.js', | |
328 | { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE } | |
329 | ) | |
330 | expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({ | |
8990357d JB |
331 | choiceRetries: 6, |
332 | runTime: { median: false }, | |
333 | waitTime: { median: false }, | |
334 | elu: { median: false } | |
335 | }) | |
336 | expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({ | |
337 | choiceRetries: 6, | |
932fc8be | 338 | runTime: { median: false }, |
5df69fab JB |
339 | waitTime: { median: false }, |
340 | elu: { median: false } | |
a20f0ba5 JB |
341 | }) |
342 | for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext | |
343 | .workerChoiceStrategies) { | |
86bf340d | 344 | expect(workerChoiceStrategy.opts).toStrictEqual({ |
8990357d | 345 | choiceRetries: 6, |
932fc8be | 346 | runTime: { median: false }, |
5df69fab JB |
347 | waitTime: { median: false }, |
348 | elu: { median: false } | |
86bf340d | 349 | }) |
a20f0ba5 | 350 | } |
87de9ff5 JB |
351 | expect( |
352 | pool.workerChoiceStrategyContext.getTaskStatisticsRequirements() | |
353 | ).toStrictEqual({ | |
932fc8be JB |
354 | runTime: { |
355 | aggregate: true, | |
356 | average: true, | |
357 | median: false | |
358 | }, | |
359 | waitTime: { | |
360 | aggregate: false, | |
361 | average: false, | |
362 | median: false | |
363 | }, | |
5df69fab | 364 | elu: { |
9adcefab JB |
365 | aggregate: true, |
366 | average: true, | |
5df69fab JB |
367 | median: false |
368 | } | |
86bf340d | 369 | }) |
9adcefab JB |
370 | pool.setWorkerChoiceStrategyOptions({ |
371 | runTime: { median: true }, | |
372 | elu: { median: true } | |
373 | }) | |
a20f0ba5 | 374 | expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({ |
8990357d | 375 | choiceRetries: 6, |
9adcefab | 376 | runTime: { median: true }, |
8990357d JB |
377 | waitTime: { median: false }, |
378 | elu: { median: true } | |
379 | }) | |
380 | expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({ | |
381 | choiceRetries: 6, | |
382 | runTime: { median: true }, | |
383 | waitTime: { median: false }, | |
9adcefab | 384 | elu: { median: true } |
a20f0ba5 JB |
385 | }) |
386 | for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext | |
387 | .workerChoiceStrategies) { | |
932fc8be | 388 | expect(workerChoiceStrategy.opts).toStrictEqual({ |
8990357d | 389 | choiceRetries: 6, |
9adcefab | 390 | runTime: { median: true }, |
8990357d | 391 | waitTime: { median: false }, |
9adcefab | 392 | elu: { median: true } |
932fc8be | 393 | }) |
a20f0ba5 | 394 | } |
87de9ff5 JB |
395 | expect( |
396 | pool.workerChoiceStrategyContext.getTaskStatisticsRequirements() | |
397 | ).toStrictEqual({ | |
932fc8be JB |
398 | runTime: { |
399 | aggregate: true, | |
400 | average: false, | |
401 | median: true | |
402 | }, | |
403 | waitTime: { | |
404 | aggregate: false, | |
405 | average: false, | |
406 | median: false | |
407 | }, | |
5df69fab | 408 | elu: { |
9adcefab | 409 | aggregate: true, |
5df69fab | 410 | average: false, |
9adcefab | 411 | median: true |
5df69fab | 412 | } |
86bf340d | 413 | }) |
9adcefab JB |
414 | pool.setWorkerChoiceStrategyOptions({ |
415 | runTime: { median: false }, | |
416 | elu: { median: false } | |
417 | }) | |
a20f0ba5 | 418 | expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({ |
8990357d JB |
419 | choiceRetries: 6, |
420 | runTime: { median: false }, | |
421 | waitTime: { median: false }, | |
422 | elu: { median: false } | |
423 | }) | |
424 | expect(pool.workerChoiceStrategyContext.opts).toStrictEqual({ | |
425 | choiceRetries: 6, | |
9adcefab | 426 | runTime: { median: false }, |
8990357d | 427 | waitTime: { median: false }, |
9adcefab | 428 | elu: { median: false } |
a20f0ba5 JB |
429 | }) |
430 | for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext | |
431 | .workerChoiceStrategies) { | |
932fc8be | 432 | expect(workerChoiceStrategy.opts).toStrictEqual({ |
8990357d | 433 | choiceRetries: 6, |
9adcefab | 434 | runTime: { median: false }, |
8990357d | 435 | waitTime: { median: false }, |
9adcefab | 436 | elu: { median: false } |
932fc8be | 437 | }) |
a20f0ba5 | 438 | } |
87de9ff5 JB |
439 | expect( |
440 | pool.workerChoiceStrategyContext.getTaskStatisticsRequirements() | |
441 | ).toStrictEqual({ | |
932fc8be JB |
442 | runTime: { |
443 | aggregate: true, | |
444 | average: true, | |
445 | median: false | |
446 | }, | |
447 | waitTime: { | |
448 | aggregate: false, | |
449 | average: false, | |
450 | median: false | |
451 | }, | |
5df69fab | 452 | elu: { |
9adcefab JB |
453 | aggregate: true, |
454 | average: true, | |
5df69fab JB |
455 | median: false |
456 | } | |
86bf340d | 457 | }) |
1f95d544 JB |
458 | expect(() => |
459 | pool.setWorkerChoiceStrategyOptions('invalidWorkerChoiceStrategyOptions') | |
460 | ).toThrowError( | |
8735b4e5 JB |
461 | new TypeError( |
462 | 'Invalid worker choice strategy options: must be a plain object' | |
463 | ) | |
1f95d544 JB |
464 | ) |
465 | expect(() => | |
466 | pool.setWorkerChoiceStrategyOptions({ weights: {} }) | |
467 | ).toThrowError( | |
8735b4e5 JB |
468 | new Error( |
469 | 'Invalid worker choice strategy options: must have a weight for each worker node' | |
470 | ) | |
1f95d544 JB |
471 | ) |
472 | expect(() => | |
473 | pool.setWorkerChoiceStrategyOptions({ measurement: 'invalidMeasurement' }) | |
474 | ).toThrowError( | |
8735b4e5 JB |
475 | new Error( |
476 | "Invalid worker choice strategy options: invalid measurement 'invalidMeasurement'" | |
477 | ) | |
1f95d544 | 478 | ) |
a20f0ba5 JB |
479 | await pool.destroy() |
480 | }) | |
481 | ||
2431bdb4 | 482 | it('Verify that pool tasks queue can be enabled/disabled', async () => { |
a20f0ba5 JB |
483 | const pool = new FixedThreadPool( |
484 | numberOfWorkers, | |
485 | './tests/worker-files/thread/testWorker.js' | |
486 | ) | |
487 | expect(pool.opts.enableTasksQueue).toBe(false) | |
488 | expect(pool.opts.tasksQueueOptions).toBeUndefined() | |
489 | pool.enableTasksQueue(true) | |
490 | expect(pool.opts.enableTasksQueue).toBe(true) | |
491 | expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 1 }) | |
492 | pool.enableTasksQueue(true, { concurrency: 2 }) | |
493 | expect(pool.opts.enableTasksQueue).toBe(true) | |
494 | expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 2 }) | |
495 | pool.enableTasksQueue(false) | |
496 | expect(pool.opts.enableTasksQueue).toBe(false) | |
497 | expect(pool.opts.tasksQueueOptions).toBeUndefined() | |
498 | await pool.destroy() | |
499 | }) | |
500 | ||
2431bdb4 | 501 | it('Verify that pool tasks queue options can be set', async () => { |
a20f0ba5 JB |
502 | const pool = new FixedThreadPool( |
503 | numberOfWorkers, | |
504 | './tests/worker-files/thread/testWorker.js', | |
505 | { enableTasksQueue: true } | |
506 | ) | |
507 | expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 1 }) | |
508 | pool.setTasksQueueOptions({ concurrency: 2 }) | |
509 | expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 2 }) | |
f0d7f803 JB |
510 | expect(() => |
511 | pool.setTasksQueueOptions('invalidTasksQueueOptions') | |
8735b4e5 JB |
512 | ).toThrowError( |
513 | new TypeError('Invalid tasks queue options: must be a plain object') | |
514 | ) | |
a20f0ba5 | 515 | expect(() => pool.setTasksQueueOptions({ concurrency: 0 })).toThrowError( |
e695d66f | 516 | new RangeError( |
8735b4e5 JB |
517 | 'Invalid worker tasks concurrency: 0 is a negative integer or zero' |
518 | ) | |
519 | ) | |
520 | expect(() => pool.setTasksQueueOptions({ concurrency: -1 })).toThrowError( | |
e695d66f | 521 | new RangeError( |
8735b4e5 JB |
522 | 'Invalid worker tasks concurrency: -1 is a negative integer or zero' |
523 | ) | |
a20f0ba5 | 524 | ) |
f0d7f803 | 525 | expect(() => pool.setTasksQueueOptions({ concurrency: 0.2 })).toThrowError( |
8735b4e5 | 526 | new TypeError('Invalid worker tasks concurrency: must be an integer') |
f0d7f803 | 527 | ) |
a20f0ba5 JB |
528 | await pool.destroy() |
529 | }) | |
530 | ||
6b27d407 JB |
531 | it('Verify that pool info is set', async () => { |
532 | let pool = new FixedThreadPool( | |
533 | numberOfWorkers, | |
534 | './tests/worker-files/thread/testWorker.js' | |
535 | ) | |
2dca6cab JB |
536 | expect(pool.info).toStrictEqual({ |
537 | version, | |
538 | type: PoolTypes.fixed, | |
539 | worker: WorkerTypes.thread, | |
540 | ready: true, | |
541 | strategy: WorkerChoiceStrategies.ROUND_ROBIN, | |
542 | minSize: numberOfWorkers, | |
543 | maxSize: numberOfWorkers, | |
544 | workerNodes: numberOfWorkers, | |
545 | idleWorkerNodes: numberOfWorkers, | |
546 | busyWorkerNodes: 0, | |
547 | executedTasks: 0, | |
548 | executingTasks: 0, | |
2dca6cab JB |
549 | failedTasks: 0 |
550 | }) | |
6b27d407 JB |
551 | await pool.destroy() |
552 | pool = new DynamicClusterPool( | |
2431bdb4 | 553 | Math.floor(numberOfWorkers / 2), |
6b27d407 | 554 | numberOfWorkers, |
ecdfbdc0 | 555 | './tests/worker-files/cluster/testWorker.js' |
6b27d407 | 556 | ) |
2dca6cab JB |
557 | expect(pool.info).toStrictEqual({ |
558 | version, | |
559 | type: PoolTypes.dynamic, | |
560 | worker: WorkerTypes.cluster, | |
561 | ready: true, | |
562 | strategy: WorkerChoiceStrategies.ROUND_ROBIN, | |
563 | minSize: Math.floor(numberOfWorkers / 2), | |
564 | maxSize: numberOfWorkers, | |
565 | workerNodes: Math.floor(numberOfWorkers / 2), | |
566 | idleWorkerNodes: Math.floor(numberOfWorkers / 2), | |
567 | busyWorkerNodes: 0, | |
568 | executedTasks: 0, | |
569 | executingTasks: 0, | |
2dca6cab JB |
570 | failedTasks: 0 |
571 | }) | |
6b27d407 JB |
572 | await pool.destroy() |
573 | }) | |
574 | ||
2431bdb4 | 575 | it('Verify that pool worker tasks usage are initialized', async () => { |
bf9549ae JB |
576 | const pool = new FixedClusterPool( |
577 | numberOfWorkers, | |
578 | './tests/worker-files/cluster/testWorker.js' | |
579 | ) | |
f06e48d8 | 580 | for (const workerNode of pool.workerNodes) { |
465b2940 | 581 | expect(workerNode.usage).toStrictEqual({ |
a4e07f72 JB |
582 | tasks: { |
583 | executed: 0, | |
584 | executing: 0, | |
585 | queued: 0, | |
df593701 | 586 | maxQueued: 0, |
a4e07f72 JB |
587 | failed: 0 |
588 | }, | |
589 | runTime: { | |
a4e07f72 JB |
590 | history: expect.any(CircularArray) |
591 | }, | |
592 | waitTime: { | |
a4e07f72 JB |
593 | history: expect.any(CircularArray) |
594 | }, | |
5df69fab JB |
595 | elu: { |
596 | idle: { | |
5df69fab JB |
597 | history: expect.any(CircularArray) |
598 | }, | |
599 | active: { | |
5df69fab | 600 | history: expect.any(CircularArray) |
f7510105 | 601 | } |
5df69fab | 602 | } |
86bf340d | 603 | }) |
f06e48d8 JB |
604 | } |
605 | await pool.destroy() | |
606 | }) | |
607 | ||
2431bdb4 JB |
608 | it('Verify that pool worker tasks queue are initialized', async () => { |
609 | let pool = new FixedClusterPool( | |
f06e48d8 JB |
610 | numberOfWorkers, |
611 | './tests/worker-files/cluster/testWorker.js' | |
612 | ) | |
613 | for (const workerNode of pool.workerNodes) { | |
614 | expect(workerNode.tasksQueue).toBeDefined() | |
29ee7e9a | 615 | expect(workerNode.tasksQueue).toBeInstanceOf(Queue) |
4d8bf9e4 | 616 | expect(workerNode.tasksQueue.size).toBe(0) |
9c16fb4b | 617 | expect(workerNode.tasksQueue.maxSize).toBe(0) |
bf9549ae | 618 | } |
fd7ebd49 | 619 | await pool.destroy() |
2431bdb4 JB |
620 | pool = new DynamicThreadPool( |
621 | Math.floor(numberOfWorkers / 2), | |
622 | numberOfWorkers, | |
623 | './tests/worker-files/thread/testWorker.js' | |
624 | ) | |
625 | for (const workerNode of pool.workerNodes) { | |
626 | expect(workerNode.tasksQueue).toBeDefined() | |
627 | expect(workerNode.tasksQueue).toBeInstanceOf(Queue) | |
628 | expect(workerNode.tasksQueue.size).toBe(0) | |
629 | expect(workerNode.tasksQueue.maxSize).toBe(0) | |
630 | } | |
631 | }) | |
632 | ||
633 | it('Verify that pool worker info are initialized', async () => { | |
634 | let pool = new FixedClusterPool( | |
635 | numberOfWorkers, | |
636 | './tests/worker-files/cluster/testWorker.js' | |
637 | ) | |
2dca6cab JB |
638 | for (const workerNode of pool.workerNodes) { |
639 | expect(workerNode.info).toStrictEqual({ | |
640 | id: expect.any(Number), | |
641 | type: WorkerTypes.cluster, | |
642 | dynamic: false, | |
643 | ready: true | |
644 | }) | |
645 | } | |
2431bdb4 JB |
646 | await pool.destroy() |
647 | pool = new DynamicThreadPool( | |
648 | Math.floor(numberOfWorkers / 2), | |
649 | numberOfWorkers, | |
650 | './tests/worker-files/thread/testWorker.js' | |
651 | ) | |
2dca6cab JB |
652 | for (const workerNode of pool.workerNodes) { |
653 | expect(workerNode.info).toStrictEqual({ | |
654 | id: expect.any(Number), | |
655 | type: WorkerTypes.thread, | |
656 | dynamic: false, | |
7884d183 | 657 | ready: true |
2dca6cab JB |
658 | }) |
659 | } | |
bf9549ae JB |
660 | }) |
661 | ||
2431bdb4 | 662 | it('Verify that pool worker tasks usage are computed', async () => { |
bf9549ae JB |
663 | const pool = new FixedClusterPool( |
664 | numberOfWorkers, | |
665 | './tests/worker-files/cluster/testWorker.js' | |
666 | ) | |
09c2d0d3 | 667 | const promises = new Set() |
fc027381 JB |
668 | const maxMultiplier = 2 |
669 | for (let i = 0; i < numberOfWorkers * maxMultiplier; i++) { | |
09c2d0d3 | 670 | promises.add(pool.execute()) |
bf9549ae | 671 | } |
f06e48d8 | 672 | for (const workerNode of pool.workerNodes) { |
465b2940 | 673 | expect(workerNode.usage).toStrictEqual({ |
a4e07f72 JB |
674 | tasks: { |
675 | executed: 0, | |
676 | executing: maxMultiplier, | |
677 | queued: 0, | |
df593701 | 678 | maxQueued: 0, |
a4e07f72 JB |
679 | failed: 0 |
680 | }, | |
681 | runTime: { | |
a4e07f72 JB |
682 | history: expect.any(CircularArray) |
683 | }, | |
684 | waitTime: { | |
a4e07f72 JB |
685 | history: expect.any(CircularArray) |
686 | }, | |
5df69fab JB |
687 | elu: { |
688 | idle: { | |
5df69fab JB |
689 | history: expect.any(CircularArray) |
690 | }, | |
691 | active: { | |
5df69fab | 692 | history: expect.any(CircularArray) |
f7510105 | 693 | } |
5df69fab | 694 | } |
86bf340d | 695 | }) |
bf9549ae JB |
696 | } |
697 | await Promise.all(promises) | |
f06e48d8 | 698 | for (const workerNode of pool.workerNodes) { |
465b2940 | 699 | expect(workerNode.usage).toStrictEqual({ |
a4e07f72 JB |
700 | tasks: { |
701 | executed: maxMultiplier, | |
702 | executing: 0, | |
703 | queued: 0, | |
df593701 | 704 | maxQueued: 0, |
a4e07f72 JB |
705 | failed: 0 |
706 | }, | |
707 | runTime: { | |
a4e07f72 JB |
708 | history: expect.any(CircularArray) |
709 | }, | |
710 | waitTime: { | |
a4e07f72 JB |
711 | history: expect.any(CircularArray) |
712 | }, | |
5df69fab JB |
713 | elu: { |
714 | idle: { | |
5df69fab JB |
715 | history: expect.any(CircularArray) |
716 | }, | |
717 | active: { | |
5df69fab | 718 | history: expect.any(CircularArray) |
f7510105 | 719 | } |
5df69fab | 720 | } |
86bf340d | 721 | }) |
bf9549ae | 722 | } |
fd7ebd49 | 723 | await pool.destroy() |
bf9549ae JB |
724 | }) |
725 | ||
2431bdb4 | 726 | it('Verify that pool worker tasks usage are reset at worker choice strategy change', async () => { |
7fd82a1c | 727 | const pool = new DynamicThreadPool( |
2431bdb4 | 728 | Math.floor(numberOfWorkers / 2), |
8f4878b7 | 729 | numberOfWorkers, |
9e619829 JB |
730 | './tests/worker-files/thread/testWorker.js' |
731 | ) | |
09c2d0d3 | 732 | const promises = new Set() |
ee9f5295 JB |
733 | const maxMultiplier = 2 |
734 | for (let i = 0; i < numberOfWorkers * maxMultiplier; i++) { | |
09c2d0d3 | 735 | promises.add(pool.execute()) |
9e619829 JB |
736 | } |
737 | await Promise.all(promises) | |
f06e48d8 | 738 | for (const workerNode of pool.workerNodes) { |
465b2940 | 739 | expect(workerNode.usage).toStrictEqual({ |
a4e07f72 JB |
740 | tasks: { |
741 | executed: expect.any(Number), | |
742 | executing: 0, | |
743 | queued: 0, | |
df593701 | 744 | maxQueued: 0, |
a4e07f72 JB |
745 | failed: 0 |
746 | }, | |
747 | runTime: { | |
a4e07f72 JB |
748 | history: expect.any(CircularArray) |
749 | }, | |
750 | waitTime: { | |
a4e07f72 JB |
751 | history: expect.any(CircularArray) |
752 | }, | |
5df69fab JB |
753 | elu: { |
754 | idle: { | |
5df69fab JB |
755 | history: expect.any(CircularArray) |
756 | }, | |
757 | active: { | |
5df69fab | 758 | history: expect.any(CircularArray) |
f7510105 | 759 | } |
5df69fab | 760 | } |
86bf340d | 761 | }) |
465b2940 | 762 | expect(workerNode.usage.tasks.executed).toBeGreaterThan(0) |
94407def JB |
763 | expect(workerNode.usage.tasks.executed).toBeLessThanOrEqual( |
764 | numberOfWorkers * maxMultiplier | |
765 | ) | |
b97d82d8 JB |
766 | expect(workerNode.usage.runTime.history.length).toBe(0) |
767 | expect(workerNode.usage.waitTime.history.length).toBe(0) | |
768 | expect(workerNode.usage.elu.idle.history.length).toBe(0) | |
769 | expect(workerNode.usage.elu.active.history.length).toBe(0) | |
9e619829 JB |
770 | } |
771 | pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE) | |
f06e48d8 | 772 | for (const workerNode of pool.workerNodes) { |
465b2940 | 773 | expect(workerNode.usage).toStrictEqual({ |
a4e07f72 JB |
774 | tasks: { |
775 | executed: 0, | |
776 | executing: 0, | |
777 | queued: 0, | |
df593701 | 778 | maxQueued: 0, |
a4e07f72 JB |
779 | failed: 0 |
780 | }, | |
781 | runTime: { | |
a4e07f72 JB |
782 | history: expect.any(CircularArray) |
783 | }, | |
784 | waitTime: { | |
a4e07f72 JB |
785 | history: expect.any(CircularArray) |
786 | }, | |
5df69fab JB |
787 | elu: { |
788 | idle: { | |
5df69fab JB |
789 | history: expect.any(CircularArray) |
790 | }, | |
791 | active: { | |
5df69fab | 792 | history: expect.any(CircularArray) |
f7510105 | 793 | } |
5df69fab | 794 | } |
86bf340d | 795 | }) |
465b2940 JB |
796 | expect(workerNode.usage.runTime.history.length).toBe(0) |
797 | expect(workerNode.usage.waitTime.history.length).toBe(0) | |
b97d82d8 JB |
798 | expect(workerNode.usage.elu.idle.history.length).toBe(0) |
799 | expect(workerNode.usage.elu.active.history.length).toBe(0) | |
ee11a4a2 | 800 | } |
fd7ebd49 | 801 | await pool.destroy() |
ee11a4a2 JB |
802 | }) |
803 | ||
a1763c54 JB |
804 | it("Verify that pool event emitter 'ready' event can register a callback", async () => { |
805 | const pool = new DynamicClusterPool( | |
2431bdb4 | 806 | Math.floor(numberOfWorkers / 2), |
164d950a | 807 | numberOfWorkers, |
a1763c54 | 808 | './tests/worker-files/cluster/testWorker.js' |
164d950a | 809 | ) |
d46660cd | 810 | let poolInfo |
a1763c54 JB |
811 | let poolReady = 0 |
812 | pool.emitter.on(PoolEvents.ready, (info) => { | |
813 | ++poolReady | |
d46660cd JB |
814 | poolInfo = info |
815 | }) | |
a1763c54 JB |
816 | await waitPoolEvents(pool, PoolEvents.ready, 1) |
817 | expect(poolReady).toBe(1) | |
d46660cd | 818 | expect(poolInfo).toStrictEqual({ |
23ccf9d7 | 819 | version, |
d46660cd | 820 | type: PoolTypes.dynamic, |
a1763c54 JB |
821 | worker: WorkerTypes.cluster, |
822 | ready: true, | |
2431bdb4 JB |
823 | strategy: WorkerChoiceStrategies.ROUND_ROBIN, |
824 | minSize: expect.any(Number), | |
825 | maxSize: expect.any(Number), | |
826 | workerNodes: expect.any(Number), | |
827 | idleWorkerNodes: expect.any(Number), | |
828 | busyWorkerNodes: expect.any(Number), | |
829 | executedTasks: expect.any(Number), | |
830 | executingTasks: expect.any(Number), | |
2431bdb4 JB |
831 | failedTasks: expect.any(Number) |
832 | }) | |
833 | await pool.destroy() | |
834 | }) | |
835 | ||
a1763c54 JB |
836 | it("Verify that pool event emitter 'busy' event can register a callback", async () => { |
837 | const pool = new FixedThreadPool( | |
2431bdb4 | 838 | numberOfWorkers, |
a1763c54 | 839 | './tests/worker-files/thread/testWorker.js' |
2431bdb4 | 840 | ) |
a1763c54 JB |
841 | const promises = new Set() |
842 | let poolBusy = 0 | |
2431bdb4 | 843 | let poolInfo |
a1763c54 JB |
844 | pool.emitter.on(PoolEvents.busy, (info) => { |
845 | ++poolBusy | |
2431bdb4 JB |
846 | poolInfo = info |
847 | }) | |
a1763c54 JB |
848 | for (let i = 0; i < numberOfWorkers * 2; i++) { |
849 | promises.add(pool.execute()) | |
850 | } | |
851 | await Promise.all(promises) | |
852 | // The `busy` event is triggered when the number of submitted tasks at once reach the number of fixed pool workers. | |
853 | // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the fixed pool. | |
854 | expect(poolBusy).toBe(numberOfWorkers + 1) | |
2431bdb4 JB |
855 | expect(poolInfo).toStrictEqual({ |
856 | version, | |
a1763c54 JB |
857 | type: PoolTypes.fixed, |
858 | worker: WorkerTypes.thread, | |
859 | ready: expect.any(Boolean), | |
2431bdb4 | 860 | strategy: WorkerChoiceStrategies.ROUND_ROBIN, |
d46660cd JB |
861 | minSize: expect.any(Number), |
862 | maxSize: expect.any(Number), | |
863 | workerNodes: expect.any(Number), | |
864 | idleWorkerNodes: expect.any(Number), | |
865 | busyWorkerNodes: expect.any(Number), | |
a4e07f72 JB |
866 | executedTasks: expect.any(Number), |
867 | executingTasks: expect.any(Number), | |
a4e07f72 | 868 | failedTasks: expect.any(Number) |
d46660cd | 869 | }) |
164d950a JB |
870 | await pool.destroy() |
871 | }) | |
872 | ||
a1763c54 JB |
873 | it("Verify that pool event emitter 'full' event can register a callback", async () => { |
874 | const pool = new DynamicThreadPool( | |
875 | Math.floor(numberOfWorkers / 2), | |
7c0ba920 JB |
876 | numberOfWorkers, |
877 | './tests/worker-files/thread/testWorker.js' | |
878 | ) | |
09c2d0d3 | 879 | const promises = new Set() |
a1763c54 | 880 | let poolFull = 0 |
d46660cd | 881 | let poolInfo |
a1763c54 JB |
882 | pool.emitter.on(PoolEvents.full, (info) => { |
883 | ++poolFull | |
d46660cd JB |
884 | poolInfo = info |
885 | }) | |
7c0ba920 | 886 | for (let i = 0; i < numberOfWorkers * 2; i++) { |
f5d14e90 | 887 | promises.add(pool.execute()) |
7c0ba920 | 888 | } |
cf597bc5 | 889 | await Promise.all(promises) |
33e6bb4c | 890 | expect(poolFull).toBe(1) |
d46660cd | 891 | expect(poolInfo).toStrictEqual({ |
23ccf9d7 | 892 | version, |
a1763c54 | 893 | type: PoolTypes.dynamic, |
d46660cd | 894 | worker: WorkerTypes.thread, |
2431bdb4 JB |
895 | ready: expect.any(Boolean), |
896 | strategy: WorkerChoiceStrategies.ROUND_ROBIN, | |
8735b4e5 JB |
897 | minSize: expect.any(Number), |
898 | maxSize: expect.any(Number), | |
899 | workerNodes: expect.any(Number), | |
900 | idleWorkerNodes: expect.any(Number), | |
901 | busyWorkerNodes: expect.any(Number), | |
902 | executedTasks: expect.any(Number), | |
903 | executingTasks: expect.any(Number), | |
904 | failedTasks: expect.any(Number) | |
905 | }) | |
906 | await pool.destroy() | |
907 | }) | |
908 | ||
3e8611a8 | 909 | it("Verify that pool event emitter 'backPressure' event can register a callback", async () => { |
b1aae695 | 910 | const pool = new FixedThreadPool( |
8735b4e5 JB |
911 | numberOfWorkers, |
912 | './tests/worker-files/thread/testWorker.js', | |
913 | { | |
914 | enableTasksQueue: true | |
915 | } | |
916 | ) | |
3e8611a8 | 917 | sinon.stub(pool, 'hasBackPressure').returns(true) |
8735b4e5 JB |
918 | const promises = new Set() |
919 | let poolBackPressure = 0 | |
920 | let poolInfo | |
921 | pool.emitter.on(PoolEvents.backPressure, (info) => { | |
922 | ++poolBackPressure | |
923 | poolInfo = info | |
924 | }) | |
b1aae695 | 925 | for (let i = 0; i < numberOfWorkers * 2; i++) { |
8735b4e5 JB |
926 | promises.add(pool.execute()) |
927 | } | |
928 | await Promise.all(promises) | |
3e8611a8 | 929 | expect(poolBackPressure).toBe(2) |
8735b4e5 JB |
930 | expect(poolInfo).toStrictEqual({ |
931 | version, | |
3e8611a8 | 932 | type: PoolTypes.fixed, |
8735b4e5 JB |
933 | worker: WorkerTypes.thread, |
934 | ready: expect.any(Boolean), | |
935 | strategy: WorkerChoiceStrategies.ROUND_ROBIN, | |
d46660cd JB |
936 | minSize: expect.any(Number), |
937 | maxSize: expect.any(Number), | |
938 | workerNodes: expect.any(Number), | |
939 | idleWorkerNodes: expect.any(Number), | |
940 | busyWorkerNodes: expect.any(Number), | |
a4e07f72 JB |
941 | executedTasks: expect.any(Number), |
942 | executingTasks: expect.any(Number), | |
3e8611a8 JB |
943 | maxQueuedTasks: expect.any(Number), |
944 | queuedTasks: expect.any(Number), | |
945 | backPressure: true, | |
a4e07f72 | 946 | failedTasks: expect.any(Number) |
d46660cd | 947 | }) |
3e8611a8 | 948 | expect(pool.hasBackPressure.called).toBe(true) |
fd7ebd49 | 949 | await pool.destroy() |
7c0ba920 | 950 | }) |
70a4f5ea | 951 | |
90d7d101 JB |
952 | it('Verify that listTaskFunctions() is working', async () => { |
953 | const dynamicThreadPool = new DynamicThreadPool( | |
954 | Math.floor(numberOfWorkers / 2), | |
955 | numberOfWorkers, | |
956 | './tests/worker-files/thread/testMultipleTaskFunctionsWorker.js' | |
957 | ) | |
958 | await waitPoolEvents(dynamicThreadPool, PoolEvents.ready, 1) | |
959 | expect(dynamicThreadPool.listTaskFunctions()).toStrictEqual([ | |
960 | 'default', | |
961 | 'jsonIntegerSerialization', | |
962 | 'factorial', | |
963 | 'fibonacci' | |
964 | ]) | |
965 | const fixedClusterPool = new FixedClusterPool( | |
966 | numberOfWorkers, | |
967 | './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js' | |
968 | ) | |
969 | await waitPoolEvents(fixedClusterPool, PoolEvents.ready, 1) | |
970 | expect(fixedClusterPool.listTaskFunctions()).toStrictEqual([ | |
971 | 'default', | |
972 | 'jsonIntegerSerialization', | |
973 | 'factorial', | |
974 | 'fibonacci' | |
975 | ]) | |
976 | }) | |
977 | ||
978 | it('Verify that multiple task functions worker is working', async () => { | |
70a4f5ea | 979 | const pool = new DynamicClusterPool( |
2431bdb4 | 980 | Math.floor(numberOfWorkers / 2), |
70a4f5ea | 981 | numberOfWorkers, |
90d7d101 | 982 | './tests/worker-files/cluster/testMultipleTaskFunctionsWorker.js' |
70a4f5ea JB |
983 | ) |
984 | const data = { n: 10 } | |
82888165 | 985 | const result0 = await pool.execute(data) |
30b963d4 | 986 | expect(result0).toStrictEqual({ ok: 1 }) |
70a4f5ea | 987 | const result1 = await pool.execute(data, 'jsonIntegerSerialization') |
30b963d4 | 988 | expect(result1).toStrictEqual({ ok: 1 }) |
70a4f5ea JB |
989 | const result2 = await pool.execute(data, 'factorial') |
990 | expect(result2).toBe(3628800) | |
991 | const result3 = await pool.execute(data, 'fibonacci') | |
024daf59 | 992 | expect(result3).toBe(55) |
5bb5be17 JB |
993 | expect(pool.info.executingTasks).toBe(0) |
994 | expect(pool.info.executedTasks).toBe(4) | |
b414b84c JB |
995 | for (const workerNode of pool.workerNodes) { |
996 | expect(workerNode.info.taskFunctions).toStrictEqual([ | |
997 | 'default', | |
998 | 'jsonIntegerSerialization', | |
999 | 'factorial', | |
1000 | 'fibonacci' | |
1001 | ]) | |
1002 | expect(workerNode.taskFunctionsUsage.size).toBe(3) | |
1003 | for (const name of pool.listTaskFunctions()) { | |
5bb5be17 JB |
1004 | expect(workerNode.getTaskFunctionWorkerUsage(name)).toStrictEqual({ |
1005 | tasks: { | |
1006 | executed: expect.any(Number), | |
1007 | executing: expect.any(Number), | |
1008 | failed: 0, | |
1009 | queued: 0 | |
1010 | }, | |
1011 | runTime: { | |
1012 | history: expect.any(CircularArray) | |
1013 | }, | |
1014 | waitTime: { | |
1015 | history: expect.any(CircularArray) | |
1016 | }, | |
1017 | elu: { | |
1018 | idle: { | |
1019 | history: expect.any(CircularArray) | |
1020 | }, | |
1021 | active: { | |
1022 | history: expect.any(CircularArray) | |
1023 | } | |
1024 | } | |
1025 | }) | |
1026 | expect( | |
1027 | workerNode.getTaskFunctionWorkerUsage(name).tasks.executing | |
1028 | ).toBeGreaterThanOrEqual(0) | |
1029 | } | |
1030 | } | |
70a4f5ea | 1031 | }) |
3ec964d6 | 1032 | }) |