1 const { expect
} = require('expect')
3 WorkerChoiceStrategies
,
7 } = require('../../../lib/index')
9 describe('Selection strategies test suite', () => {
13 it('Verify that WorkerChoiceStrategies enumeration provides string values', () => {
14 expect(WorkerChoiceStrategies
.ROUND_ROBIN
).toBe('ROUND_ROBIN')
15 expect(WorkerChoiceStrategies
.LESS_USED
).toBe('LESS_USED')
16 expect(WorkerChoiceStrategies
.LESS_BUSY
).toBe('LESS_BUSY')
17 expect(WorkerChoiceStrategies
.FAIR_SHARE
).toBe('FAIR_SHARE')
18 expect(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
).toBe(
19 'WEIGHTED_ROUND_ROBIN'
23 it('Verify ROUND_ROBIN strategy is the default at pool creation', async () => {
24 const pool
= new DynamicThreadPool(
27 './tests/worker-files/thread/testWorker.js'
29 expect(pool
.opts
.workerChoiceStrategy
).toBe(
30 WorkerChoiceStrategies
.ROUND_ROBIN
32 // We need to clean up the resources after our test
36 it('Verify ROUND_ROBIN strategy is taken at pool creation', async () => {
37 const pool
= new FixedThreadPool(
39 './tests/worker-files/thread/testWorker.js',
40 { workerChoiceStrategy
: WorkerChoiceStrategies
.ROUND_ROBIN
}
42 expect(pool
.opts
.workerChoiceStrategy
).toBe(
43 WorkerChoiceStrategies
.ROUND_ROBIN
46 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
47 WorkerChoiceStrategies
.ROUND_ROBIN
50 // We need to clean up the resources after our test
54 it('Verify ROUND_ROBIN strategy can be set after pool creation', async () => {
55 const pool
= new DynamicThreadPool(
58 './tests/worker-files/thread/testWorker.js'
60 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.ROUND_ROBIN
)
61 expect(pool
.opts
.workerChoiceStrategy
).toBe(
62 WorkerChoiceStrategies
.ROUND_ROBIN
64 // We need to clean up the resources after our test
68 it('Verify ROUND_ROBIN strategy default tasks usage statistics requirements', async () => {
69 let pool
= new FixedThreadPool(
71 './tests/worker-files/thread/testWorker.js'
73 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.ROUND_ROBIN
)
75 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
78 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
81 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
84 pool
= new DynamicThreadPool(
87 './tests/worker-files/thread/testWorker.js'
89 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.ROUND_ROBIN
)
91 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
94 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
97 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
99 // We need to clean up the resources after our test
103 it('Verify ROUND_ROBIN strategy can be run in a fixed pool', async () => {
104 const pool
= new FixedThreadPool(
106 './tests/worker-files/thread/testWorker.js',
107 { workerChoiceStrategy
: WorkerChoiceStrategies
.ROUND_ROBIN
}
109 expect(pool
.opts
.workerChoiceStrategy
).toBe(
110 WorkerChoiceStrategies
.ROUND_ROBIN
112 // TODO: Create a better test to cover `RoundRobinWorkerChoiceStrategy#choose`
114 for (let i
= 0; i
< max
* 2; i
++) {
115 promises
.push(pool
.execute())
117 await Promise
.all(promises
)
118 // We need to clean up the resources after our test
122 it('Verify ROUND_ROBIN strategy can be run in a dynamic pool', async () => {
123 const pool
= new DynamicThreadPool(
126 './tests/worker-files/thread/testWorker.js',
127 { workerChoiceStrategy
: WorkerChoiceStrategies
.ROUND_ROBIN
}
129 expect(pool
.opts
.workerChoiceStrategy
).toBe(
130 WorkerChoiceStrategies
.ROUND_ROBIN
132 // TODO: Create a better test to cover `RoundRobinWorkerChoiceStrategy#choose`
134 for (let i
= 0; i
< max
* 2; i
++) {
135 promises
.push(pool
.execute())
137 await Promise
.all(promises
)
138 // We need to clean up the resources after our test
142 it('Verify ROUND_ROBIN strategy runtime behavior', async () => {
143 let pool
= new FixedClusterPool(
145 './tests/worker-files/cluster/testWorker.js'
147 let results
= new Set()
148 for (let i
= 0; i
< max
; i
++) {
149 results
.add(pool
.chooseWorkerNode()[1].worker
.id
)
151 expect(results
.size
).toBe(max
)
153 pool
= new FixedThreadPool(max
, './tests/worker-files/thread/testWorker.js')
155 for (let i
= 0; i
< max
; i
++) {
156 results
.add(pool
.chooseWorkerNode()[1].worker
.threadId
)
158 expect(results
.size
).toBe(max
)
162 it('Verify ROUND_ROBIN strategy internals are resets after setting it', async () => {
163 let pool
= new FixedThreadPool(
165 './tests/worker-files/thread/testWorker.js',
166 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
169 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
170 WorkerChoiceStrategies
.ROUND_ROBIN
173 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.ROUND_ROBIN
)
175 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
176 WorkerChoiceStrategies
.ROUND_ROBIN
180 pool
= new DynamicThreadPool(
183 './tests/worker-files/thread/testWorker.js',
184 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
187 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
188 WorkerChoiceStrategies
.ROUND_ROBIN
191 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.ROUND_ROBIN
)
193 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
194 WorkerChoiceStrategies
.ROUND_ROBIN
197 // We need to clean up the resources after our test
201 it('Verify LESS_USED strategy is taken at pool creation', async () => {
202 const pool
= new FixedThreadPool(
204 './tests/worker-files/thread/testWorker.js',
205 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_USED
}
207 expect(pool
.opts
.workerChoiceStrategy
).toBe(
208 WorkerChoiceStrategies
.LESS_USED
210 // We need to clean up the resources after our test
214 it('Verify LESS_USED strategy can be set after pool creation', async () => {
215 const pool
= new FixedThreadPool(
217 './tests/worker-files/thread/testWorker.js'
219 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.LESS_USED
)
220 expect(pool
.opts
.workerChoiceStrategy
).toBe(
221 WorkerChoiceStrategies
.LESS_USED
223 // We need to clean up the resources after our test
227 it('Verify LESS_USED strategy default tasks usage statistics requirements', async () => {
228 let pool
= new FixedThreadPool(
230 './tests/worker-files/thread/testWorker.js'
232 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.LESS_USED
)
234 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
237 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
240 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
243 pool
= new DynamicThreadPool(
246 './tests/worker-files/thread/testWorker.js'
248 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.LESS_USED
)
250 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
253 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
256 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
258 // We need to clean up the resources after our test
262 it('Verify LESS_USED strategy can be run in a fixed pool', async () => {
263 const pool
= new FixedThreadPool(
265 './tests/worker-files/thread/testWorker.js',
266 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_USED
}
268 // TODO: Create a better test to cover `LessUsedWorkerChoiceStrategy#choose`
270 for (let i
= 0; i
< max
* 2; i
++) {
271 promises
.push(pool
.execute())
273 await Promise
.all(promises
)
274 // We need to clean up the resources after our test
278 it('Verify LESS_USED strategy can be run in a dynamic pool', async () => {
279 const pool
= new DynamicThreadPool(
282 './tests/worker-files/thread/testWorker.js',
283 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_USED
}
285 // TODO: Create a better test to cover `LessUsedWorkerChoiceStrategy#choose`
287 for (let i
= 0; i
< max
* 2; i
++) {
288 promises
.push(pool
.execute())
290 await Promise
.all(promises
)
291 // We need to clean up the resources after our test
295 it('Verify LESS_BUSY strategy is taken at pool creation', async () => {
296 const pool
= new FixedThreadPool(
298 './tests/worker-files/thread/testWorker.js',
299 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_BUSY
}
301 expect(pool
.opts
.workerChoiceStrategy
).toBe(
302 WorkerChoiceStrategies
.LESS_BUSY
304 // We need to clean up the resources after our test
308 it('Verify LESS_BUSY strategy can be set after pool creation', async () => {
309 const pool
= new FixedThreadPool(
311 './tests/worker-files/thread/testWorker.js'
313 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.LESS_BUSY
)
314 expect(pool
.opts
.workerChoiceStrategy
).toBe(
315 WorkerChoiceStrategies
.LESS_BUSY
317 // We need to clean up the resources after our test
321 it('Verify LESS_BUSY strategy default tasks usage statistics requirements', async () => {
322 let pool
= new FixedThreadPool(
324 './tests/worker-files/thread/testWorker.js'
326 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.LESS_BUSY
)
328 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
331 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
334 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
337 pool
= new DynamicThreadPool(
340 './tests/worker-files/thread/testWorker.js'
342 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.LESS_BUSY
)
344 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
347 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
350 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
352 // We need to clean up the resources after our test
356 it('Verify LESS_BUSY strategy can be run in a fixed pool', async () => {
357 const pool
= new FixedThreadPool(
359 './tests/worker-files/thread/testWorker.js',
360 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_BUSY
}
362 // TODO: Create a better test to cover `LessBusyWorkerChoiceStrategy#choose`
364 for (let i
= 0; i
< max
* 2; i
++) {
365 promises
.push(pool
.execute())
367 await Promise
.all(promises
)
368 // We need to clean up the resources after our test
372 it('Verify LESS_BUSY strategy can be run in a dynamic pool', async () => {
373 const pool
= new DynamicThreadPool(
376 './tests/worker-files/thread/testWorker.js',
377 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_BUSY
}
379 // TODO: Create a better test to cover `LessBusyWorkerChoiceStrategy#choose`
381 for (let i
= 0; i
< max
* 2; i
++) {
382 promises
.push(pool
.execute())
384 await Promise
.all(promises
)
385 // We need to clean up the resources after our test
389 it('Verify FAIR_SHARE strategy is taken at pool creation', async () => {
390 const pool
= new FixedThreadPool(
392 './tests/worker-files/thread/testWorker.js',
393 { workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
}
395 expect(pool
.opts
.workerChoiceStrategy
).toBe(
396 WorkerChoiceStrategies
.FAIR_SHARE
398 for (const workerNodeKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
399 .get(WorkerChoiceStrategies
.FAIR_SHARE
)
400 .workerLastVirtualTaskTimestamp
.keys()) {
402 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
403 .get(WorkerChoiceStrategies
.FAIR_SHARE
)
404 .workerLastVirtualTaskTimestamp
.get(workerNodeKey
).start
407 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
408 .get(WorkerChoiceStrategies
.FAIR_SHARE
)
409 .workerLastVirtualTaskTimestamp
.get(workerNodeKey
).end
412 // We need to clean up the resources after our test
416 it('Verify FAIR_SHARE strategy can be set after pool creation', async () => {
417 const pool
= new FixedThreadPool(
419 './tests/worker-files/thread/testWorker.js'
421 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.FAIR_SHARE
)
422 expect(pool
.opts
.workerChoiceStrategy
).toBe(
423 WorkerChoiceStrategies
.FAIR_SHARE
425 // We need to clean up the resources after our test
429 it('Verify FAIR_SHARE strategy default tasks usage statistics requirements', async () => {
430 let pool
= new FixedThreadPool(
432 './tests/worker-files/thread/testWorker.js'
434 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.FAIR_SHARE
)
436 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
439 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
442 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
445 pool
= new DynamicThreadPool(
448 './tests/worker-files/thread/testWorker.js'
450 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.FAIR_SHARE
)
452 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
455 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
458 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
460 // We need to clean up the resources after our test
464 it('Verify FAIR_SHARE strategy can be run in a fixed pool', async () => {
465 const pool
= new FixedThreadPool(
467 './tests/worker-files/thread/testWorker.js',
468 { workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
}
470 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
472 for (let i
= 0; i
< max
* 2; i
++) {
473 promises
.push(pool
.execute())
475 await Promise
.all(promises
)
477 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
478 WorkerChoiceStrategies
.FAIR_SHARE
479 ).workerLastVirtualTaskTimestamp
.size
480 ).toBe(pool
.workerNodes
.length
)
481 // We need to clean up the resources after our test
485 it('Verify FAIR_SHARE strategy can be run in a dynamic pool', async () => {
486 const pool
= new DynamicThreadPool(
489 './tests/worker-files/thread/testWorker.js',
490 { workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
}
492 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
494 const maxMultiplier
= 2
495 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
496 promises
.push(pool
.execute())
498 await Promise
.all(promises
)
499 // if (process.platform !== 'win32') {
501 // pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
502 // WorkerChoiceStrategies.FAIR_SHARE
503 // ).workerLastVirtualTaskTimestamp.size
504 // ).toBe(pool.workerNodes.length)
506 // We need to clean up the resources after our test
510 it('Verify FAIR_SHARE strategy internals are resets after setting it', async () => {
511 let pool
= new FixedThreadPool(
513 './tests/worker-files/thread/testWorker.js'
516 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
517 WorkerChoiceStrategies
.FAIR_SHARE
518 ).workerLastVirtualTaskTimestamp
520 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.FAIR_SHARE
)
521 for (const workerNodeKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
522 .get(WorkerChoiceStrategies
.FAIR_SHARE
)
523 .workerLastVirtualTaskTimestamp
.keys()) {
525 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
526 .get(WorkerChoiceStrategies
.FAIR_SHARE
)
527 .workerLastVirtualTaskTimestamp
.get(workerNodeKey
).start
530 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
531 .get(WorkerChoiceStrategies
.FAIR_SHARE
)
532 .workerLastVirtualTaskTimestamp
.get(workerNodeKey
).end
536 pool
= new DynamicThreadPool(
539 './tests/worker-files/thread/testWorker.js'
542 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
543 WorkerChoiceStrategies
.FAIR_SHARE
544 ).workerLastVirtualTaskTimestamp
546 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.FAIR_SHARE
)
547 for (const workerNodeKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
548 .get(WorkerChoiceStrategies
.FAIR_SHARE
)
549 .workerLastVirtualTaskTimestamp
.keys()) {
551 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
552 .get(WorkerChoiceStrategies
.FAIR_SHARE
)
553 .workerLastVirtualTaskTimestamp
.get(workerNodeKey
).start
556 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
557 .get(WorkerChoiceStrategies
.FAIR_SHARE
)
558 .workerLastVirtualTaskTimestamp
.get(workerNodeKey
).end
561 // We need to clean up the resources after our test
565 it('Verify WEIGHTED_ROUND_ROBIN strategy is taken at pool creation', async () => {
566 const pool
= new FixedThreadPool(
568 './tests/worker-files/thread/testWorker.js',
569 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
571 expect(pool
.opts
.workerChoiceStrategy
).toBe(
572 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
575 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
576 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
577 ).currentWorkerNodeId
580 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
581 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
582 ).defaultWorkerWeight
584 for (const workerNodeKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
585 .get(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
586 .workersTaskRunTime
.keys()) {
588 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
589 .get(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
590 .workersTaskRunTime
.get(workerNodeKey
).weight
593 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
594 .get(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
595 .workersTaskRunTime
.get(workerNodeKey
).runTime
598 // We need to clean up the resources after our test
602 it('Verify WEIGHTED_ROUND_ROBIN strategy can be set after pool creation', async () => {
603 const pool
= new FixedThreadPool(
605 './tests/worker-files/thread/testWorker.js'
607 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
608 expect(pool
.opts
.workerChoiceStrategy
).toBe(
609 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
611 // We need to clean up the resources after our test
615 it('Verify WEIGHTED_ROUND_ROBIN strategy default tasks usage statistics requirements', async () => {
616 let pool
= new FixedThreadPool(
618 './tests/worker-files/thread/testWorker.js'
620 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
622 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
625 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
628 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
631 pool
= new DynamicThreadPool(
634 './tests/worker-files/thread/testWorker.js'
636 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
638 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
641 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
644 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
646 // We need to clean up the resources after our test
650 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a fixed pool', async () => {
651 const pool
= new FixedThreadPool(
653 './tests/worker-files/thread/testWorker.js',
654 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
656 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
658 for (let i
= 0; i
< max
* 2; i
++) {
659 promises
.push(pool
.execute())
661 await Promise
.all(promises
)
663 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
664 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
665 ).workersTaskRunTime
.size
666 ).toBe(pool
.workerNodes
.length
)
667 // We need to clean up the resources after our test
671 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a dynamic pool', async () => {
672 const pool
= new DynamicThreadPool(
675 './tests/worker-files/thread/testWorker.js',
676 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
678 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
680 const maxMultiplier
=
681 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
682 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
683 ).defaultWorkerWeight
* 50
684 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
685 promises
.push(pool
.execute())
687 await Promise
.all(promises
)
688 if (process
.platform
!== 'win32') {
690 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
691 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
692 ).workersTaskRunTime
.size
693 ).toBe(pool
.workerNodes
.length
)
695 // We need to clean up the resources after our test
699 it('Verify WEIGHTED_ROUND_ROBIN strategy internals are resets after setting it', async () => {
700 let pool
= new FixedThreadPool(
702 './tests/worker-files/thread/testWorker.js'
705 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
706 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
707 ).currentWorkerNodeId
710 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
711 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
712 ).defaultWorkerWeight
715 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
716 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
719 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
721 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
722 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
723 ).currentWorkerNodeId
726 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
727 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
728 ).defaultWorkerWeight
730 for (const workerNodeKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
731 .get(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
732 .workersTaskRunTime
.keys()) {
734 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
735 .get(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
736 .workersTaskRunTime
.get(workerNodeKey
).runTime
740 pool
= new DynamicThreadPool(
743 './tests/worker-files/thread/testWorker.js'
746 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
747 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
748 ).currentWorkerNodeId
751 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
752 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
753 ).defaultWorkerWeight
756 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
757 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
760 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
762 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
763 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
764 ).currentWorkerNodeId
767 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
768 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
769 ).defaultWorkerWeight
771 for (const workerNodeKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
772 .get(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
773 .workersTaskRunTime
.keys()) {
775 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
776 .get(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
777 .workersTaskRunTime
.get(workerNodeKey
).runTime
780 // We need to clean up the resources after our test
784 it('Verify unknown strategies throw error', () => {
787 new DynamicThreadPool(
790 './tests/worker-files/thread/testWorker.js',
791 { workerChoiceStrategy
: 'UNKNOWN_STRATEGY' }
794 new Error("Invalid worker choice strategy 'UNKNOWN_STRATEGY'")