Merge pull request #773 from poolifier/elu-strategy
[poolifier.git] / tests / pools / abstract / abstract-pool.test.js
CommitLineData
a61a0724 1const { expect } = require('expect')
e843b904 2const {
70a4f5ea 3 DynamicClusterPool,
9e619829 4 DynamicThreadPool,
aee46736 5 FixedClusterPool,
e843b904 6 FixedThreadPool,
aee46736 7 PoolEvents,
6b27d407 8 WorkerChoiceStrategies,
184855e6
JB
9 PoolTypes,
10 WorkerTypes
cdace0e5 11} = require('../../../lib')
78099a15 12const { CircularArray } = require('../../../lib/circular-array')
29ee7e9a 13const { Queue } = require('../../../lib/queue')
e1ffb94f
JB
14
15describe('Abstract pool test suite', () => {
fc027381 16 const numberOfWorkers = 2
a8884ffd 17 class StubPoolWithRemoveAllWorker extends FixedThreadPool {
e1ffb94f 18 removeAllWorker () {
d4aeae5a 19 this.workerNodes = []
c923ce56 20 this.promiseResponseMap.clear()
e1ffb94f 21 }
3ec964d6 22 }
a8884ffd 23 class StubPoolWithIsMain extends FixedThreadPool {
e1ffb94f
JB
24 isMain () {
25 return false
26 }
3ec964d6 27 }
3ec964d6 28
3ec964d6 29 it('Simulate pool creation from a non main thread/process', () => {
8d3782fa
JB
30 expect(
31 () =>
a8884ffd 32 new StubPoolWithIsMain(
7c0ba920 33 numberOfWorkers,
8d3782fa
JB
34 './tests/worker-files/thread/testWorker.js',
35 {
36 errorHandler: e => console.error(e)
37 }
38 )
d4aeae5a 39 ).toThrowError('Cannot start a pool from a worker!')
3ec964d6 40 })
c510fea7
APA
41
42 it('Verify that filePath is checked', () => {
292ad316
JB
43 const expectedError = new Error(
44 'Please specify a file with a worker implementation'
45 )
7c0ba920 46 expect(() => new FixedThreadPool(numberOfWorkers)).toThrowError(
292ad316 47 expectedError
8d3782fa 48 )
7c0ba920 49 expect(() => new FixedThreadPool(numberOfWorkers, '')).toThrowError(
292ad316 50 expectedError
8d3782fa
JB
51 )
52 })
53
54 it('Verify that numberOfWorkers is checked', () => {
55 expect(() => new FixedThreadPool()).toThrowError(
d4aeae5a 56 'Cannot instantiate a pool without specifying the number of workers'
8d3782fa
JB
57 )
58 })
59
60 it('Verify that a negative number of workers is checked', () => {
61 expect(
62 () =>
63 new FixedClusterPool(-1, './tests/worker-files/cluster/testWorker.js')
64 ).toThrowError(
473c717a
JB
65 new RangeError(
66 'Cannot instantiate a pool with a negative number of workers'
67 )
8d3782fa
JB
68 )
69 })
70
71 it('Verify that a non integer number of workers is checked', () => {
72 expect(
73 () =>
74 new FixedThreadPool(0.25, './tests/worker-files/thread/testWorker.js')
75 ).toThrowError(
473c717a 76 new TypeError(
0d80593b 77 'Cannot instantiate a pool with a non safe integer number of workers'
8d3782fa
JB
78 )
79 )
c510fea7 80 })
7c0ba920 81
fd7ebd49 82 it('Verify that pool options are checked', async () => {
7c0ba920
JB
83 let pool = new FixedThreadPool(
84 numberOfWorkers,
85 './tests/worker-files/thread/testWorker.js'
86 )
7c0ba920 87 expect(pool.emitter).toBeDefined()
1f68cede
JB
88 expect(pool.opts.enableEvents).toBe(true)
89 expect(pool.opts.restartWorkerOnError).toBe(true)
ff733df7 90 expect(pool.opts.enableTasksQueue).toBe(false)
d4aeae5a 91 expect(pool.opts.tasksQueueOptions).toBeUndefined()
e843b904
JB
92 expect(pool.opts.workerChoiceStrategy).toBe(
93 WorkerChoiceStrategies.ROUND_ROBIN
94 )
da309861 95 expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
932fc8be
JB
96 runTime: { median: false },
97 waitTime: { median: false }
da309861 98 })
35cf1c03
JB
99 expect(pool.opts.messageHandler).toBeUndefined()
100 expect(pool.opts.errorHandler).toBeUndefined()
101 expect(pool.opts.onlineHandler).toBeUndefined()
102 expect(pool.opts.exitHandler).toBeUndefined()
fd7ebd49 103 await pool.destroy()
35cf1c03 104 const testHandler = () => console.log('test handler executed')
7c0ba920
JB
105 pool = new FixedThreadPool(
106 numberOfWorkers,
107 './tests/worker-files/thread/testWorker.js',
108 {
e4543b14 109 workerChoiceStrategy: WorkerChoiceStrategies.LEAST_USED,
49be33fe 110 workerChoiceStrategyOptions: {
932fc8be 111 runTime: { median: true },
fc027381 112 weights: { 0: 300, 1: 200 }
49be33fe 113 },
35cf1c03 114 enableEvents: false,
1f68cede 115 restartWorkerOnError: false,
ff733df7 116 enableTasksQueue: true,
d4aeae5a 117 tasksQueueOptions: { concurrency: 2 },
35cf1c03
JB
118 messageHandler: testHandler,
119 errorHandler: testHandler,
120 onlineHandler: testHandler,
121 exitHandler: testHandler
7c0ba920
JB
122 }
123 )
7c0ba920 124 expect(pool.emitter).toBeUndefined()
1f68cede
JB
125 expect(pool.opts.enableEvents).toBe(false)
126 expect(pool.opts.restartWorkerOnError).toBe(false)
ff733df7 127 expect(pool.opts.enableTasksQueue).toBe(true)
d4aeae5a 128 expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 2 })
e843b904 129 expect(pool.opts.workerChoiceStrategy).toBe(
e4543b14 130 WorkerChoiceStrategies.LEAST_USED
e843b904 131 )
da309861 132 expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
932fc8be 133 runTime: { median: true },
fc027381 134 weights: { 0: 300, 1: 200 }
da309861 135 })
35cf1c03
JB
136 expect(pool.opts.messageHandler).toStrictEqual(testHandler)
137 expect(pool.opts.errorHandler).toStrictEqual(testHandler)
138 expect(pool.opts.onlineHandler).toStrictEqual(testHandler)
139 expect(pool.opts.exitHandler).toStrictEqual(testHandler)
fd7ebd49 140 await pool.destroy()
7c0ba920
JB
141 })
142
a20f0ba5 143 it('Verify that pool options are validated', async () => {
d4aeae5a
JB
144 expect(
145 () =>
146 new FixedThreadPool(
147 numberOfWorkers,
148 './tests/worker-files/thread/testWorker.js',
149 {
150 enableTasksQueue: true,
151 tasksQueueOptions: { concurrency: 0 }
152 }
153 )
154 ).toThrowError("Invalid worker tasks concurrency '0'")
155 expect(
156 () =>
157 new FixedThreadPool(
158 numberOfWorkers,
159 './tests/worker-files/thread/testWorker.js',
160 {
161 workerChoiceStrategy: 'invalidStrategy'
162 }
163 )
164 ).toThrowError("Invalid worker choice strategy 'invalidStrategy'")
49be33fe
JB
165 expect(
166 () =>
167 new FixedThreadPool(
168 numberOfWorkers,
169 './tests/worker-files/thread/testWorker.js',
170 {
171 workerChoiceStrategyOptions: { weights: {} }
172 }
173 )
174 ).toThrowError(
175 'Invalid worker choice strategy options: must have a weight for each worker node'
176 )
d4aeae5a
JB
177 })
178
a20f0ba5
JB
179 it('Verify that worker choice strategy options can be set', async () => {
180 const pool = new FixedThreadPool(
181 numberOfWorkers,
182 './tests/worker-files/thread/testWorker.js',
183 { workerChoiceStrategy: WorkerChoiceStrategies.FAIR_SHARE }
184 )
185 expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
932fc8be
JB
186 runTime: { median: false },
187 waitTime: { median: false }
a20f0ba5
JB
188 })
189 for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
190 .workerChoiceStrategies) {
86bf340d 191 expect(workerChoiceStrategy.opts).toStrictEqual({
932fc8be
JB
192 runTime: { median: false },
193 waitTime: { median: false }
86bf340d 194 })
a20f0ba5 195 }
87de9ff5
JB
196 expect(
197 pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
198 ).toStrictEqual({
932fc8be
JB
199 runTime: {
200 aggregate: true,
201 average: true,
202 median: false
203 },
204 waitTime: {
205 aggregate: false,
206 average: false,
207 median: false
208 },
d44d5953 209 elu: false
86bf340d 210 })
932fc8be 211 pool.setWorkerChoiceStrategyOptions({ runTime: { median: true } })
a20f0ba5 212 expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
932fc8be 213 runTime: { median: true }
a20f0ba5
JB
214 })
215 for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
216 .workerChoiceStrategies) {
932fc8be
JB
217 expect(workerChoiceStrategy.opts).toStrictEqual({
218 runTime: { median: true }
219 })
a20f0ba5 220 }
87de9ff5
JB
221 expect(
222 pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
223 ).toStrictEqual({
932fc8be
JB
224 runTime: {
225 aggregate: true,
226 average: false,
227 median: true
228 },
229 waitTime: {
230 aggregate: false,
231 average: false,
232 median: false
233 },
d44d5953 234 elu: false
86bf340d 235 })
932fc8be 236 pool.setWorkerChoiceStrategyOptions({ runTime: { median: false } })
a20f0ba5 237 expect(pool.opts.workerChoiceStrategyOptions).toStrictEqual({
932fc8be 238 runTime: { median: false }
a20f0ba5
JB
239 })
240 for (const [, workerChoiceStrategy] of pool.workerChoiceStrategyContext
241 .workerChoiceStrategies) {
932fc8be
JB
242 expect(workerChoiceStrategy.opts).toStrictEqual({
243 runTime: { median: false }
244 })
a20f0ba5 245 }
87de9ff5
JB
246 expect(
247 pool.workerChoiceStrategyContext.getTaskStatisticsRequirements()
248 ).toStrictEqual({
932fc8be
JB
249 runTime: {
250 aggregate: true,
251 average: true,
252 median: false
253 },
254 waitTime: {
255 aggregate: false,
256 average: false,
257 median: false
258 },
d44d5953 259 elu: false
86bf340d 260 })
a20f0ba5
JB
261 await pool.destroy()
262 })
263
264 it('Verify that tasks queue can be enabled/disabled', async () => {
265 const pool = new FixedThreadPool(
266 numberOfWorkers,
267 './tests/worker-files/thread/testWorker.js'
268 )
269 expect(pool.opts.enableTasksQueue).toBe(false)
270 expect(pool.opts.tasksQueueOptions).toBeUndefined()
271 pool.enableTasksQueue(true)
272 expect(pool.opts.enableTasksQueue).toBe(true)
273 expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 1 })
274 pool.enableTasksQueue(true, { concurrency: 2 })
275 expect(pool.opts.enableTasksQueue).toBe(true)
276 expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 2 })
277 pool.enableTasksQueue(false)
278 expect(pool.opts.enableTasksQueue).toBe(false)
279 expect(pool.opts.tasksQueueOptions).toBeUndefined()
280 await pool.destroy()
281 })
282
283 it('Verify that tasks queue options can be set', async () => {
284 const pool = new FixedThreadPool(
285 numberOfWorkers,
286 './tests/worker-files/thread/testWorker.js',
287 { enableTasksQueue: true }
288 )
289 expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 1 })
290 pool.setTasksQueueOptions({ concurrency: 2 })
291 expect(pool.opts.tasksQueueOptions).toStrictEqual({ concurrency: 2 })
292 expect(() => pool.setTasksQueueOptions({ concurrency: 0 })).toThrowError(
293 "Invalid worker tasks concurrency '0'"
294 )
295 await pool.destroy()
296 })
297
6b27d407
JB
298 it('Verify that pool info is set', async () => {
299 let pool = new FixedThreadPool(
300 numberOfWorkers,
301 './tests/worker-files/thread/testWorker.js'
302 )
303 expect(pool.info).toStrictEqual({
304 type: PoolTypes.fixed,
184855e6 305 worker: WorkerTypes.thread,
6b27d407
JB
306 minSize: numberOfWorkers,
307 maxSize: numberOfWorkers,
308 workerNodes: numberOfWorkers,
309 idleWorkerNodes: numberOfWorkers,
310 busyWorkerNodes: 0,
a4e07f72
JB
311 executedTasks: 0,
312 executingTasks: 0,
6b27d407 313 queuedTasks: 0,
a4e07f72
JB
314 maxQueuedTasks: 0,
315 failedTasks: 0
6b27d407
JB
316 })
317 await pool.destroy()
318 pool = new DynamicClusterPool(
319 numberOfWorkers,
320 numberOfWorkers * 2,
321 './tests/worker-files/thread/testWorker.js'
322 )
323 expect(pool.info).toStrictEqual({
324 type: PoolTypes.dynamic,
184855e6 325 worker: WorkerTypes.cluster,
6b27d407
JB
326 minSize: numberOfWorkers,
327 maxSize: numberOfWorkers * 2,
328 workerNodes: numberOfWorkers,
329 idleWorkerNodes: numberOfWorkers,
330 busyWorkerNodes: 0,
a4e07f72
JB
331 executedTasks: 0,
332 executingTasks: 0,
6b27d407 333 queuedTasks: 0,
a4e07f72
JB
334 maxQueuedTasks: 0,
335 failedTasks: 0
6b27d407
JB
336 })
337 await pool.destroy()
338 })
339
9d16d33e 340 it('Simulate worker not found', async () => {
a8884ffd 341 const pool = new StubPoolWithRemoveAllWorker(
10fcfaf4
JB
342 numberOfWorkers,
343 './tests/worker-files/cluster/testWorker.js',
344 {
10fcfaf4
JB
345 errorHandler: e => console.error(e)
346 }
347 )
d4aeae5a 348 expect(pool.workerNodes.length).toBe(numberOfWorkers)
10fcfaf4
JB
349 // Simulate worker not found.
350 pool.removeAllWorker()
d4aeae5a 351 expect(pool.workerNodes.length).toBe(0)
fd7ebd49 352 await pool.destroy()
bf9549ae
JB
353 })
354
fd7ebd49 355 it('Verify that worker pool tasks usage are initialized', async () => {
bf9549ae
JB
356 const pool = new FixedClusterPool(
357 numberOfWorkers,
358 './tests/worker-files/cluster/testWorker.js'
359 )
f06e48d8 360 for (const workerNode of pool.workerNodes) {
a4e07f72
JB
361 expect(workerNode.workerUsage).toStrictEqual({
362 tasks: {
363 executed: 0,
364 executing: 0,
365 queued: 0,
366 failed: 0
367 },
368 runTime: {
932fc8be 369 aggregate: 0,
a4e07f72
JB
370 average: 0,
371 median: 0,
372 history: expect.any(CircularArray)
373 },
374 waitTime: {
932fc8be 375 aggregate: 0,
a4e07f72
JB
376 average: 0,
377 median: 0,
378 history: expect.any(CircularArray)
379 },
d44d5953 380 elu: undefined
86bf340d 381 })
f06e48d8
JB
382 }
383 await pool.destroy()
384 })
385
386 it('Verify that worker pool tasks queue are initialized', async () => {
387 const pool = new FixedClusterPool(
388 numberOfWorkers,
389 './tests/worker-files/cluster/testWorker.js'
390 )
391 for (const workerNode of pool.workerNodes) {
392 expect(workerNode.tasksQueue).toBeDefined()
29ee7e9a 393 expect(workerNode.tasksQueue).toBeInstanceOf(Queue)
4d8bf9e4 394 expect(workerNode.tasksQueue.size).toBe(0)
bf9549ae 395 }
fd7ebd49 396 await pool.destroy()
bf9549ae
JB
397 })
398
399 it('Verify that worker pool tasks usage are computed', async () => {
400 const pool = new FixedClusterPool(
401 numberOfWorkers,
402 './tests/worker-files/cluster/testWorker.js'
403 )
09c2d0d3 404 const promises = new Set()
fc027381
JB
405 const maxMultiplier = 2
406 for (let i = 0; i < numberOfWorkers * maxMultiplier; i++) {
09c2d0d3 407 promises.add(pool.execute())
bf9549ae 408 }
f06e48d8 409 for (const workerNode of pool.workerNodes) {
a4e07f72
JB
410 expect(workerNode.workerUsage).toStrictEqual({
411 tasks: {
412 executed: 0,
413 executing: maxMultiplier,
414 queued: 0,
415 failed: 0
416 },
417 runTime: {
932fc8be 418 aggregate: 0,
a4e07f72
JB
419 average: 0,
420 median: 0,
421 history: expect.any(CircularArray)
422 },
423 waitTime: {
932fc8be 424 aggregate: 0,
a4e07f72
JB
425 average: 0,
426 median: 0,
427 history: expect.any(CircularArray)
428 },
d44d5953 429 elu: undefined
86bf340d 430 })
bf9549ae
JB
431 }
432 await Promise.all(promises)
f06e48d8 433 for (const workerNode of pool.workerNodes) {
a4e07f72
JB
434 expect(workerNode.workerUsage).toStrictEqual({
435 tasks: {
436 executed: maxMultiplier,
437 executing: 0,
438 queued: 0,
439 failed: 0
440 },
441 runTime: {
932fc8be 442 aggregate: 0,
a4e07f72
JB
443 average: 0,
444 median: 0,
445 history: expect.any(CircularArray)
446 },
447 waitTime: {
932fc8be 448 aggregate: 0,
a4e07f72
JB
449 average: 0,
450 median: 0,
451 history: expect.any(CircularArray)
452 },
d44d5953 453 elu: undefined
86bf340d 454 })
bf9549ae 455 }
fd7ebd49 456 await pool.destroy()
bf9549ae
JB
457 })
458
ee11a4a2 459 it('Verify that worker pool tasks usage are reset at worker choice strategy change', async () => {
7fd82a1c 460 const pool = new DynamicThreadPool(
9e619829 461 numberOfWorkers,
8f4878b7 462 numberOfWorkers,
9e619829
JB
463 './tests/worker-files/thread/testWorker.js'
464 )
09c2d0d3 465 const promises = new Set()
ee9f5295
JB
466 const maxMultiplier = 2
467 for (let i = 0; i < numberOfWorkers * maxMultiplier; i++) {
09c2d0d3 468 promises.add(pool.execute())
9e619829
JB
469 }
470 await Promise.all(promises)
f06e48d8 471 for (const workerNode of pool.workerNodes) {
a4e07f72
JB
472 expect(workerNode.workerUsage).toStrictEqual({
473 tasks: {
474 executed: expect.any(Number),
475 executing: 0,
476 queued: 0,
477 failed: 0
478 },
479 runTime: {
932fc8be 480 aggregate: 0,
a4e07f72
JB
481 average: 0,
482 median: 0,
483 history: expect.any(CircularArray)
484 },
485 waitTime: {
932fc8be 486 aggregate: 0,
a4e07f72
JB
487 average: 0,
488 median: 0,
489 history: expect.any(CircularArray)
490 },
d44d5953 491 elu: undefined
86bf340d 492 })
a4e07f72
JB
493 expect(workerNode.workerUsage.tasks.executed).toBeGreaterThan(0)
494 expect(workerNode.workerUsage.tasks.executed).toBeLessThanOrEqual(
495 maxMultiplier
496 )
9e619829
JB
497 }
498 pool.setWorkerChoiceStrategy(WorkerChoiceStrategies.FAIR_SHARE)
f06e48d8 499 for (const workerNode of pool.workerNodes) {
a4e07f72
JB
500 expect(workerNode.workerUsage).toStrictEqual({
501 tasks: {
502 executed: 0,
503 executing: 0,
504 queued: 0,
505 failed: 0
506 },
507 runTime: {
932fc8be 508 aggregate: 0,
a4e07f72
JB
509 average: 0,
510 median: 0,
511 history: expect.any(CircularArray)
512 },
513 waitTime: {
932fc8be 514 aggregate: 0,
a4e07f72
JB
515 average: 0,
516 median: 0,
517 history: expect.any(CircularArray)
518 },
d44d5953 519 elu: undefined
86bf340d 520 })
a4e07f72
JB
521 expect(workerNode.workerUsage.runTime.history.length).toBe(0)
522 expect(workerNode.workerUsage.waitTime.history.length).toBe(0)
ee11a4a2 523 }
fd7ebd49 524 await pool.destroy()
ee11a4a2
JB
525 })
526
164d950a
JB
527 it("Verify that pool event emitter 'full' event can register a callback", async () => {
528 const pool = new DynamicThreadPool(
529 numberOfWorkers,
530 numberOfWorkers,
531 './tests/worker-files/thread/testWorker.js'
532 )
09c2d0d3 533 const promises = new Set()
164d950a 534 let poolFull = 0
d46660cd
JB
535 let poolInfo
536 pool.emitter.on(PoolEvents.full, info => {
537 ++poolFull
538 poolInfo = info
539 })
164d950a 540 for (let i = 0; i < numberOfWorkers * 2; i++) {
f5d14e90 541 promises.add(pool.execute())
164d950a
JB
542 }
543 await Promise.all(promises)
594bfb84 544 // The `full` event is triggered when the number of submitted tasks at once reach the max number of workers in the dynamic pool.
fc027381
JB
545 // So in total numberOfWorkers * 2 times for a loop submitting up to numberOfWorkers * 2 tasks to the dynamic pool with min = max = numberOfWorkers.
546 expect(poolFull).toBe(numberOfWorkers * 2)
d46660cd
JB
547 expect(poolInfo).toStrictEqual({
548 type: PoolTypes.dynamic,
549 worker: WorkerTypes.thread,
550 minSize: expect.any(Number),
551 maxSize: expect.any(Number),
552 workerNodes: expect.any(Number),
553 idleWorkerNodes: expect.any(Number),
554 busyWorkerNodes: expect.any(Number),
a4e07f72
JB
555 executedTasks: expect.any(Number),
556 executingTasks: expect.any(Number),
d46660cd 557 queuedTasks: expect.any(Number),
a4e07f72
JB
558 maxQueuedTasks: expect.any(Number),
559 failedTasks: expect.any(Number)
d46660cd 560 })
164d950a
JB
561 await pool.destroy()
562 })
563
cf597bc5 564 it("Verify that pool event emitter 'busy' event can register a callback", async () => {
7c0ba920
JB
565 const pool = new FixedThreadPool(
566 numberOfWorkers,
567 './tests/worker-files/thread/testWorker.js'
568 )
09c2d0d3 569 const promises = new Set()
7c0ba920 570 let poolBusy = 0
d46660cd
JB
571 let poolInfo
572 pool.emitter.on(PoolEvents.busy, info => {
573 ++poolBusy
574 poolInfo = info
575 })
7c0ba920 576 for (let i = 0; i < numberOfWorkers * 2; i++) {
f5d14e90 577 promises.add(pool.execute())
7c0ba920 578 }
cf597bc5 579 await Promise.all(promises)
14916bf9
JB
580 // The `busy` event is triggered when the number of submitted tasks at once reach the number of fixed pool workers.
581 // So in total numberOfWorkers + 1 times for a loop submitting up to numberOfWorkers * 2 tasks to the fixed pool.
582 expect(poolBusy).toBe(numberOfWorkers + 1)
d46660cd
JB
583 expect(poolInfo).toStrictEqual({
584 type: PoolTypes.fixed,
585 worker: WorkerTypes.thread,
586 minSize: expect.any(Number),
587 maxSize: expect.any(Number),
588 workerNodes: expect.any(Number),
589 idleWorkerNodes: expect.any(Number),
590 busyWorkerNodes: expect.any(Number),
a4e07f72
JB
591 executedTasks: expect.any(Number),
592 executingTasks: expect.any(Number),
d46660cd 593 queuedTasks: expect.any(Number),
a4e07f72
JB
594 maxQueuedTasks: expect.any(Number),
595 failedTasks: expect.any(Number)
d46660cd 596 })
fd7ebd49 597 await pool.destroy()
7c0ba920 598 })
70a4f5ea
JB
599
600 it('Verify that multiple tasks worker is working', async () => {
601 const pool = new DynamicClusterPool(
602 numberOfWorkers,
603 numberOfWorkers * 2,
604 './tests/worker-files/cluster/testMultiTasksWorker.js'
605 )
606 const data = { n: 10 }
82888165
JB
607 const result0 = await pool.execute(data)
608 expect(result0).toBe(false)
70a4f5ea
JB
609 const result1 = await pool.execute(data, 'jsonIntegerSerialization')
610 expect(result1).toBe(false)
611 const result2 = await pool.execute(data, 'factorial')
612 expect(result2).toBe(3628800)
613 const result3 = await pool.execute(data, 'fibonacci')
614 expect(result3).toBe(89)
615 })
3ec964d6 616})