1 const { expect
} = require('expect')
3 WorkerChoiceStrategies
,
7 } = require('../../../lib')
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
.LEAST_USED
).toBe('LEAST_USED')
16 expect(WorkerChoiceStrategies
.LEAST_BUSY
).toBe('LEAST_BUSY')
17 expect(WorkerChoiceStrategies
.FAIR_SHARE
).toBe('FAIR_SHARE')
18 expect(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
).toBe(
19 'WEIGHTED_ROUND_ROBIN'
21 expect(WorkerChoiceStrategies
.INTERLEAVED_WEIGHTED_ROUND_ROBIN
).toBe(
22 'INTERLEAVED_WEIGHTED_ROUND_ROBIN'
26 it('Verify ROUND_ROBIN strategy is the default at pool creation', async () => {
27 const pool
= new DynamicThreadPool(
30 './tests/worker-files/thread/testWorker.js'
32 expect(pool
.opts
.workerChoiceStrategy
).toBe(
33 WorkerChoiceStrategies
.ROUND_ROBIN
35 // We need to clean up the resources after our test
39 it('Verify available strategies are taken at pool creation', async () => {
40 for (const workerChoiceStrategy
of Object
.values(WorkerChoiceStrategies
)) {
41 const pool
= new FixedThreadPool(
43 './tests/worker-files/thread/testWorker.js',
44 { workerChoiceStrategy
}
46 expect(pool
.opts
.workerChoiceStrategy
).toBe(workerChoiceStrategy
)
47 expect(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
).toBe(
54 it('Verify available strategies can be set after pool creation', async () => {
55 for (const workerChoiceStrategy
of Object
.values(WorkerChoiceStrategies
)) {
56 const pool
= new DynamicThreadPool(
59 './tests/worker-files/thread/testWorker.js'
61 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
62 expect(pool
.opts
.workerChoiceStrategy
).toBe(workerChoiceStrategy
)
63 expect(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
).toBe(
70 it('Verify available strategies default internals at pool creation', async () => {
71 const pool
= new FixedThreadPool(
73 './tests/worker-files/thread/testWorker.js'
75 for (const workerChoiceStrategy
of Object
.values(WorkerChoiceStrategies
)) {
76 if (workerChoiceStrategy
=== WorkerChoiceStrategies
.ROUND_ROBIN
) {
78 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
82 } else if (workerChoiceStrategy
=== WorkerChoiceStrategies
.FAIR_SHARE
) {
84 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
86 ).workersVirtualTaskEndTimestamp
87 ).toBeInstanceOf(Array
)
89 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
91 ).workersVirtualTaskEndTimestamp
.length
94 workerChoiceStrategy
=== WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
97 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
102 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
104 ).defaultWorkerWeight
107 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
109 ).workerVirtualTaskRunTime
116 it('Verify ROUND_ROBIN strategy default tasks usage statistics requirements', async () => {
117 const workerChoiceStrategy
= WorkerChoiceStrategies
.ROUND_ROBIN
118 let pool
= new FixedThreadPool(
120 './tests/worker-files/thread/testWorker.js',
121 { workerChoiceStrategy
}
124 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
127 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
130 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
133 pool
= new DynamicThreadPool(
136 './tests/worker-files/thread/testWorker.js',
137 { workerChoiceStrategy
}
140 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
143 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
146 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
148 // We need to clean up the resources after our test
152 it('Verify ROUND_ROBIN strategy can be run in a fixed pool', async () => {
153 const pool
= new FixedThreadPool(
155 './tests/worker-files/thread/testWorker.js',
156 { workerChoiceStrategy
: WorkerChoiceStrategies
.ROUND_ROBIN
}
158 // TODO: Create a better test to cover `RoundRobinWorkerChoiceStrategy#choose`
159 const maxMultiplier
= 2
160 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
163 // We need to clean up the resources after our test
167 it('Verify ROUND_ROBIN strategy can be run in a dynamic pool', async () => {
168 const pool
= new DynamicThreadPool(
171 './tests/worker-files/thread/testWorker.js',
172 { workerChoiceStrategy
: WorkerChoiceStrategies
.ROUND_ROBIN
}
174 // TODO: Create a better test to cover `RoundRobinWorkerChoiceStrategy#choose`
175 const maxMultiplier
= 2
176 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
179 // We need to clean up the resources after our test
183 it('Verify ROUND_ROBIN strategy runtime behavior', async () => {
184 const workerChoiceStrategy
= WorkerChoiceStrategies
.ROUND_ROBIN
185 let pool
= new FixedClusterPool(
187 './tests/worker-files/cluster/testWorker.js',
188 { workerChoiceStrategy
}
190 let results
= new Set()
191 for (let i
= 0; i
< max
; i
++) {
192 results
.add(pool
.workerNodes
[pool
.chooseWorkerNode()].worker
.id
)
194 expect(results
.size
).toBe(max
)
196 pool
= new FixedThreadPool(
198 './tests/worker-files/thread/testWorker.js',
199 { workerChoiceStrategy
}
202 for (let i
= 0; i
< max
; i
++) {
203 results
.add(pool
.workerNodes
[pool
.chooseWorkerNode()].worker
.threadId
)
205 expect(results
.size
).toBe(max
)
209 it('Verify ROUND_ROBIN strategy internals are resets after setting it', async () => {
210 const workerChoiceStrategy
= WorkerChoiceStrategies
.ROUND_ROBIN
211 let pool
= new FixedThreadPool(
213 './tests/worker-files/thread/testWorker.js',
214 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
217 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
221 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
223 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
224 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
228 pool
= new DynamicThreadPool(
231 './tests/worker-files/thread/testWorker.js',
232 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
235 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
239 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
241 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
242 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
245 // We need to clean up the resources after our test
249 it('Verify LEAST_USED strategy default tasks usage statistics requirements', async () => {
250 const workerChoiceStrategy
= WorkerChoiceStrategies
.LEAST_USED
251 let pool
= new FixedThreadPool(
253 './tests/worker-files/thread/testWorker.js',
254 { workerChoiceStrategy
}
257 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
260 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
263 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
266 pool
= new DynamicThreadPool(
269 './tests/worker-files/thread/testWorker.js',
270 { workerChoiceStrategy
}
273 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
276 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
279 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
281 // We need to clean up the resources after our test
285 it('Verify LEAST_USED strategy can be run in a fixed pool', async () => {
286 const pool
= new FixedThreadPool(
288 './tests/worker-files/thread/testWorker.js',
289 { workerChoiceStrategy
: WorkerChoiceStrategies
.LEAST_USED
}
291 // TODO: Create a better test to cover `LeastUsedWorkerChoiceStrategy#choose`
292 const maxMultiplier
= 2
293 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
296 // We need to clean up the resources after our test
300 it('Verify LEAST_USED strategy can be run in a dynamic pool', async () => {
301 const pool
= new DynamicThreadPool(
304 './tests/worker-files/thread/testWorker.js',
305 { workerChoiceStrategy
: WorkerChoiceStrategies
.LEAST_USED
}
307 // TODO: Create a better test to cover `LeastUsedWorkerChoiceStrategy#choose`
308 const maxMultiplier
= 2
309 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
312 // We need to clean up the resources after our test
316 it('Verify LEAST_BUSY strategy default tasks usage statistics requirements', async () => {
317 const workerChoiceStrategy
= WorkerChoiceStrategies
.LEAST_BUSY
318 let pool
= new FixedThreadPool(
320 './tests/worker-files/thread/testWorker.js',
321 { workerChoiceStrategy
}
324 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
327 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
330 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
333 pool
= new DynamicThreadPool(
336 './tests/worker-files/thread/testWorker.js',
337 { workerChoiceStrategy
}
340 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
343 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
346 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
348 // We need to clean up the resources after our test
352 it('Verify LEAST_BUSY strategy can be run in a fixed pool', async () => {
353 const pool
= new FixedThreadPool(
355 './tests/worker-files/thread/testWorker.js',
356 { workerChoiceStrategy
: WorkerChoiceStrategies
.LEAST_BUSY
}
358 // TODO: Create a better test to cover `LeastBusyWorkerChoiceStrategy#choose`
359 const maxMultiplier
= 2
360 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
363 // We need to clean up the resources after our test
367 it('Verify LEAST_BUSY strategy can be run in a dynamic pool', async () => {
368 const pool
= new DynamicThreadPool(
371 './tests/worker-files/thread/testWorker.js',
372 { workerChoiceStrategy
: WorkerChoiceStrategies
.LEAST_BUSY
}
374 // TODO: Create a better test to cover `LeastBusyWorkerChoiceStrategy#choose`
375 const maxMultiplier
= 2
376 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
379 // We need to clean up the resources after our test
383 it('Verify FAIR_SHARE strategy default tasks usage statistics requirements', async () => {
384 const workerChoiceStrategy
= WorkerChoiceStrategies
.FAIR_SHARE
385 let pool
= new FixedThreadPool(
387 './tests/worker-files/thread/testWorker.js',
388 { workerChoiceStrategy
}
391 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
394 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
397 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
400 pool
= new DynamicThreadPool(
403 './tests/worker-files/thread/testWorker.js',
404 { workerChoiceStrategy
}
407 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
410 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
413 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
415 // We need to clean up the resources after our test
419 it('Verify FAIR_SHARE strategy can be run in a fixed pool', async () => {
420 const pool
= new FixedThreadPool(
422 './tests/worker-files/thread/testWorker.js',
423 { workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
}
425 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
426 const maxMultiplier
= 2
427 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
430 for (const workerNode
of pool
.workerNodes
) {
431 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
432 expect(workerNode
.tasksUsage
.avgRunTime
).toBeGreaterThanOrEqual(0)
433 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
434 expect(workerNode
.tasksUsage
.medRunTime
).toBe(0)
437 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
438 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
439 ).workersVirtualTaskEndTimestamp
.length
440 ).toBe(pool
.workerNodes
.length
)
441 // We need to clean up the resources after our test
445 it('Verify FAIR_SHARE strategy can be run in a dynamic pool', async () => {
446 const pool
= new DynamicThreadPool(
449 './tests/worker-files/thread/testWorker.js',
450 { workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
}
452 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
453 const maxMultiplier
= 2
454 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
457 for (const workerNode
of pool
.workerNodes
) {
458 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
459 expect(workerNode
.tasksUsage
.avgRunTime
).toBeGreaterThanOrEqual(0)
460 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
461 expect(workerNode
.tasksUsage
.medRunTime
).toBe(0)
464 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
465 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
466 ).workersVirtualTaskEndTimestamp
.length
467 ).toBe(pool
.workerNodes
.length
)
468 // We need to clean up the resources after our test
472 it('Verify FAIR_SHARE strategy can be run in a dynamic pool with median runtime statistic', async () => {
473 const pool
= new DynamicThreadPool(
476 './tests/worker-files/thread/testWorker.js',
478 workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
,
479 workerChoiceStrategyOptions
: {
484 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
485 const maxMultiplier
= 2
486 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
489 for (const workerNode
of pool
.workerNodes
) {
490 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
491 expect(workerNode
.tasksUsage
.avgRunTime
).toBe(0)
492 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
493 expect(workerNode
.tasksUsage
.medRunTime
).toBeGreaterThanOrEqual(0)
496 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
497 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
498 ).workersVirtualTaskEndTimestamp
.length
499 ).toBe(pool
.workerNodes
.length
)
500 // We need to clean up the resources after our test
504 it('Verify FAIR_SHARE strategy internals are resets after setting it', async () => {
505 const workerChoiceStrategy
= WorkerChoiceStrategies
.FAIR_SHARE
506 let pool
= new FixedThreadPool(
508 './tests/worker-files/thread/testWorker.js'
511 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
513 ).workersVirtualTaskEndTimestamp
514 ).toBeInstanceOf(Array
)
516 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
518 ).workersVirtualTaskEndTimestamp
.length
520 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
522 ).workersVirtualTaskEndTimestamp
[0] = performance
.now()
524 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
526 ).workersVirtualTaskEndTimestamp
.length
528 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
530 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
532 ).workersVirtualTaskEndTimestamp
533 ).toBeInstanceOf(Array
)
535 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
537 ).workersVirtualTaskEndTimestamp
.length
540 pool
= new DynamicThreadPool(
543 './tests/worker-files/thread/testWorker.js'
546 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
548 ).workersVirtualTaskEndTimestamp
549 ).toBeInstanceOf(Array
)
551 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
553 ).workersVirtualTaskEndTimestamp
.length
555 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
557 ).workersVirtualTaskEndTimestamp
[0] = performance
.now()
559 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
561 ).workersVirtualTaskEndTimestamp
.length
563 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
565 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
567 ).workersVirtualTaskEndTimestamp
568 ).toBeInstanceOf(Array
)
570 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
572 ).workersVirtualTaskEndTimestamp
.length
574 // We need to clean up the resources after our test
578 it('Verify WEIGHTED_ROUND_ROBIN strategy default tasks usage statistics requirements', async () => {
579 const workerChoiceStrategy
= WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
580 let pool
= new FixedThreadPool(
582 './tests/worker-files/thread/testWorker.js',
583 { workerChoiceStrategy
}
586 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
589 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
592 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
595 pool
= new DynamicThreadPool(
598 './tests/worker-files/thread/testWorker.js',
599 { workerChoiceStrategy
}
602 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
605 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
608 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
610 // We need to clean up the resources after our test
614 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a fixed pool', async () => {
615 const pool
= new FixedThreadPool(
617 './tests/worker-files/thread/testWorker.js',
618 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
620 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
621 const maxMultiplier
= 2
622 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
625 for (const workerNode
of pool
.workerNodes
) {
626 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
627 expect(workerNode
.tasksUsage
.avgRunTime
).toBeGreaterThanOrEqual(0)
628 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
629 expect(workerNode
.tasksUsage
.medRunTime
).toBe(0)
632 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
633 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
634 ).defaultWorkerWeight
637 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
638 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
639 ).workerVirtualTaskRunTime
640 ).toBeGreaterThanOrEqual(0)
641 // We need to clean up the resources after our test
645 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a dynamic pool', async () => {
646 const pool
= new DynamicThreadPool(
649 './tests/worker-files/thread/testWorker.js',
650 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
652 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
653 const maxMultiplier
= 2
654 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
657 for (const workerNode
of pool
.workerNodes
) {
658 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
659 expect(workerNode
.tasksUsage
.avgRunTime
).toBeGreaterThanOrEqual(0)
660 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
661 expect(workerNode
.tasksUsage
.medRunTime
).toBe(0)
664 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
665 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
666 ).defaultWorkerWeight
669 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
670 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
671 ).workerVirtualTaskRunTime
672 ).toBeGreaterThanOrEqual(0)
673 // We need to clean up the resources after our test
677 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a dynamic pool with median runtime statistic', async () => {
678 const pool
= new DynamicThreadPool(
681 './tests/worker-files/thread/testWorker.js',
683 workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
,
684 workerChoiceStrategyOptions
: {
689 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
690 const maxMultiplier
= 2
691 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
694 for (const workerNode
of pool
.workerNodes
) {
695 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
696 expect(workerNode
.tasksUsage
.avgRunTime
).toBe(0)
697 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
698 expect(workerNode
.tasksUsage
.medRunTime
).toBeGreaterThanOrEqual(0)
701 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
702 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
703 ).defaultWorkerWeight
706 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
707 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
708 ).workerVirtualTaskRunTime
709 ).toBeGreaterThanOrEqual(0)
710 // We need to clean up the resources after our test
714 it('Verify WEIGHTED_ROUND_ROBIN strategy internals are resets after setting it', async () => {
715 const workerChoiceStrategy
= WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
716 let pool
= new FixedThreadPool(
718 './tests/worker-files/thread/testWorker.js'
721 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
723 ).currentWorkerNodeId
726 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
728 ).defaultWorkerWeight
731 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
733 ).workerVirtualTaskRunTime
735 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
737 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
738 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
739 ).currentWorkerNodeId
742 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
743 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
744 ).defaultWorkerWeight
747 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
749 ).workerVirtualTaskRunTime
752 pool
= new DynamicThreadPool(
755 './tests/worker-files/thread/testWorker.js'
758 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
760 ).currentWorkerNodeId
763 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
765 ).defaultWorkerWeight
768 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
770 ).workerVirtualTaskRunTime
772 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
774 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
775 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
776 ).currentWorkerNodeId
779 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
780 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
781 ).defaultWorkerWeight
784 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
786 ).workerVirtualTaskRunTime
788 // We need to clean up the resources after our test
792 it('Verify unknown strategy throw error', () => {
795 new DynamicThreadPool(
798 './tests/worker-files/thread/testWorker.js',
799 { workerChoiceStrategy
: 'UNKNOWN_STRATEGY' }
801 ).toThrowError("Invalid worker choice strategy 'UNKNOWN_STRATEGY'")