1 const { expect
} = require('expect')
3 WorkerChoiceStrategies
,
7 } = require('../../../lib')
8 const { CircularArray
} = require('../../../lib/circular-array')
10 describe('Selection strategies test suite', () => {
14 it('Verify that WorkerChoiceStrategies enumeration provides string values', () => {
15 expect(WorkerChoiceStrategies
.ROUND_ROBIN
).toBe('ROUND_ROBIN')
16 expect(WorkerChoiceStrategies
.LEAST_USED
).toBe('LEAST_USED')
17 expect(WorkerChoiceStrategies
.LEAST_BUSY
).toBe('LEAST_BUSY')
18 expect(WorkerChoiceStrategies
.FAIR_SHARE
).toBe('FAIR_SHARE')
19 expect(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
).toBe(
20 'WEIGHTED_ROUND_ROBIN'
24 it('Verify ROUND_ROBIN strategy is the default at pool creation', async () => {
25 const pool
= new DynamicThreadPool(
28 './tests/worker-files/thread/testWorker.js'
30 expect(pool
.opts
.workerChoiceStrategy
).toBe(
31 WorkerChoiceStrategies
.ROUND_ROBIN
33 // We need to clean up the resources after our test
37 it('Verify available strategies are taken at pool creation', async () => {
38 for (const workerChoiceStrategy
of Object
.values(WorkerChoiceStrategies
)) {
39 const pool
= new FixedThreadPool(
41 './tests/worker-files/thread/testWorker.js',
42 { workerChoiceStrategy
}
44 expect(pool
.opts
.workerChoiceStrategy
).toBe(workerChoiceStrategy
)
45 expect(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
).toBe(
52 it('Verify available strategies can be set after pool creation', async () => {
53 for (const workerChoiceStrategy
of Object
.values(WorkerChoiceStrategies
)) {
54 const pool
= new DynamicThreadPool(
57 './tests/worker-files/thread/testWorker.js'
59 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
60 expect(pool
.opts
.workerChoiceStrategy
).toBe(workerChoiceStrategy
)
61 expect(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
).toBe(
68 it('Verify available strategies default internals at pool creation', async () => {
69 const pool
= new FixedThreadPool(
71 './tests/worker-files/thread/testWorker.js'
73 for (const workerChoiceStrategy
of Object
.values(WorkerChoiceStrategies
)) {
74 if (workerChoiceStrategy
=== WorkerChoiceStrategies
.ROUND_ROBIN
) {
76 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
80 } else if (workerChoiceStrategy
=== WorkerChoiceStrategies
.FAIR_SHARE
) {
82 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
84 ).workersVirtualTaskEndTimestamp
85 ).toBeInstanceOf(Array
)
87 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
89 ).workersVirtualTaskEndTimestamp
.length
92 workerChoiceStrategy
=== WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
95 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
100 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
102 ).defaultWorkerWeight
105 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
107 ).workerVirtualTaskRunTime
114 it('Verify ROUND_ROBIN strategy default tasks usage statistics requirements', async () => {
115 const workerChoiceStrategy
= WorkerChoiceStrategies
.ROUND_ROBIN
116 let pool
= new FixedThreadPool(
118 './tests/worker-files/thread/testWorker.js',
119 { workerChoiceStrategy
}
122 pool
.workerChoiceStrategyContext
.getRequiredStatistics()
132 pool
= new DynamicThreadPool(
135 './tests/worker-files/thread/testWorker.js',
136 { workerChoiceStrategy
}
139 pool
.workerChoiceStrategyContext
.getRequiredStatistics()
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()
267 pool
= new DynamicThreadPool(
270 './tests/worker-files/thread/testWorker.js',
271 { workerChoiceStrategy
}
274 pool
.workerChoiceStrategyContext
.getRequiredStatistics()
283 // We need to clean up the resources after our test
287 it('Verify LEAST_USED strategy can be run in a fixed pool', async () => {
288 const pool
= new FixedThreadPool(
290 './tests/worker-files/thread/testWorker.js',
291 { workerChoiceStrategy
: WorkerChoiceStrategies
.LEAST_USED
}
293 // TODO: Create a better test to cover `LeastUsedWorkerChoiceStrategy#choose`
294 const maxMultiplier
= 2
295 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
298 // We need to clean up the resources after our test
302 it('Verify LEAST_USED strategy can be run in a dynamic pool', async () => {
303 const pool
= new DynamicThreadPool(
306 './tests/worker-files/thread/testWorker.js',
307 { workerChoiceStrategy
: WorkerChoiceStrategies
.LEAST_USED
}
309 // TODO: Create a better test to cover `LeastUsedWorkerChoiceStrategy#choose`
310 const maxMultiplier
= 2
311 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
314 // We need to clean up the resources after our test
318 it('Verify LEAST_BUSY strategy default tasks usage statistics requirements', async () => {
319 const workerChoiceStrategy
= WorkerChoiceStrategies
.LEAST_BUSY
320 let pool
= new FixedThreadPool(
322 './tests/worker-files/thread/testWorker.js',
323 { workerChoiceStrategy
}
326 pool
.workerChoiceStrategyContext
.getRequiredStatistics()
336 pool
= new DynamicThreadPool(
339 './tests/worker-files/thread/testWorker.js',
340 { workerChoiceStrategy
}
343 pool
.workerChoiceStrategyContext
.getRequiredStatistics()
352 // We need to clean up the resources after our test
356 it('Verify LEAST_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
.LEAST_BUSY
}
362 // TODO: Create a better test to cover `LeastBusyWorkerChoiceStrategy#choose`
363 const maxMultiplier
= 2
364 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
367 // We need to clean up the resources after our test
371 it('Verify LEAST_BUSY strategy can be run in a dynamic pool', async () => {
372 const pool
= new DynamicThreadPool(
375 './tests/worker-files/thread/testWorker.js',
376 { workerChoiceStrategy
: WorkerChoiceStrategies
.LEAST_BUSY
}
378 // TODO: Create a better test to cover `LeastBusyWorkerChoiceStrategy#choose`
379 const maxMultiplier
= 2
380 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
383 // We need to clean up the resources after our test
387 it('Verify FAIR_SHARE strategy default tasks usage statistics requirements', async () => {
388 const workerChoiceStrategy
= WorkerChoiceStrategies
.FAIR_SHARE
389 let pool
= new FixedThreadPool(
391 './tests/worker-files/thread/testWorker.js',
392 { workerChoiceStrategy
}
395 pool
.workerChoiceStrategyContext
.getRequiredStatistics()
405 pool
= new DynamicThreadPool(
408 './tests/worker-files/thread/testWorker.js',
409 { workerChoiceStrategy
}
412 pool
.workerChoiceStrategyContext
.getRequiredStatistics()
421 // We need to clean up the resources after our test
425 it('Verify FAIR_SHARE strategy can be run in a fixed pool', async () => {
426 const pool
= new FixedThreadPool(
428 './tests/worker-files/thread/testWorker.js',
429 { workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
}
431 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
432 const maxMultiplier
= 2
433 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
436 for (const workerNode
of pool
.workerNodes
) {
437 expect(workerNode
.tasksUsage
).toStrictEqual({
440 runTime
: expect
.any(Number
),
441 runTimeHistory
: expect
.any(CircularArray
),
442 avgRunTime
: expect
.any(Number
),
445 waitTimeHistory
: expect
.any(CircularArray
),
450 expect(workerNode
.tasksUsage
.avgRunTime
).toBeGreaterThanOrEqual(0)
453 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
454 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
455 ).workersVirtualTaskEndTimestamp
.length
456 ).toBe(pool
.workerNodes
.length
)
457 // We need to clean up the resources after our test
461 it('Verify FAIR_SHARE strategy can be run in a dynamic pool', async () => {
462 const pool
= new DynamicThreadPool(
465 './tests/worker-files/thread/testWorker.js',
466 { workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
}
468 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
469 const maxMultiplier
= 2
470 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
473 for (const workerNode
of pool
.workerNodes
) {
474 expect(workerNode
.tasksUsage
).toStrictEqual({
475 run
: max
* maxMultiplier
,
477 runTime
: expect
.any(Number
),
478 runTimeHistory
: expect
.any(CircularArray
),
479 avgRunTime
: expect
.any(Number
),
482 waitTimeHistory
: expect
.any(CircularArray
),
487 expect(workerNode
.tasksUsage
.avgRunTime
).toBeGreaterThanOrEqual(0)
490 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
491 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
492 ).workersVirtualTaskEndTimestamp
.length
493 ).toBe(pool
.workerNodes
.length
)
494 // We need to clean up the resources after our test
498 it('Verify FAIR_SHARE strategy can be run in a dynamic pool with median runtime statistic', async () => {
499 const pool
= new DynamicThreadPool(
502 './tests/worker-files/thread/testWorker.js',
504 workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
,
505 workerChoiceStrategyOptions
: {
510 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
511 const maxMultiplier
= 2
512 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
515 for (const workerNode
of pool
.workerNodes
) {
516 expect(workerNode
.tasksUsage
).toStrictEqual({
517 run
: max
* maxMultiplier
,
519 runTime
: expect
.any(Number
),
520 runTimeHistory
: expect
.any(CircularArray
),
522 medRunTime
: expect
.any(Number
),
524 waitTimeHistory
: expect
.any(CircularArray
),
529 expect(workerNode
.tasksUsage
.medRunTime
).toBeGreaterThanOrEqual(0)
532 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
533 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
534 ).workersVirtualTaskEndTimestamp
.length
535 ).toBe(pool
.workerNodes
.length
)
536 // We need to clean up the resources after our test
540 it('Verify FAIR_SHARE strategy internals are resets after setting it', async () => {
541 const workerChoiceStrategy
= WorkerChoiceStrategies
.FAIR_SHARE
542 let pool
= new FixedThreadPool(
544 './tests/worker-files/thread/testWorker.js'
547 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
549 ).workersVirtualTaskEndTimestamp
550 ).toBeInstanceOf(Array
)
552 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
554 ).workersVirtualTaskEndTimestamp
.length
556 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
558 ).workersVirtualTaskEndTimestamp
[0] = performance
.now()
560 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
562 ).workersVirtualTaskEndTimestamp
.length
564 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
566 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
568 ).workersVirtualTaskEndTimestamp
569 ).toBeInstanceOf(Array
)
571 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
573 ).workersVirtualTaskEndTimestamp
.length
576 pool
= new DynamicThreadPool(
579 './tests/worker-files/thread/testWorker.js'
582 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
584 ).workersVirtualTaskEndTimestamp
585 ).toBeInstanceOf(Array
)
587 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
589 ).workersVirtualTaskEndTimestamp
.length
591 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
593 ).workersVirtualTaskEndTimestamp
[0] = performance
.now()
595 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
597 ).workersVirtualTaskEndTimestamp
.length
599 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
601 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
603 ).workersVirtualTaskEndTimestamp
604 ).toBeInstanceOf(Array
)
606 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
608 ).workersVirtualTaskEndTimestamp
.length
610 // We need to clean up the resources after our test
614 it('Verify WEIGHTED_ROUND_ROBIN strategy default tasks usage statistics requirements', async () => {
615 const workerChoiceStrategy
= WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
616 let pool
= new FixedThreadPool(
618 './tests/worker-files/thread/testWorker.js',
619 { workerChoiceStrategy
}
622 pool
.workerChoiceStrategyContext
.getRequiredStatistics()
632 pool
= new DynamicThreadPool(
635 './tests/worker-files/thread/testWorker.js',
636 { workerChoiceStrategy
}
639 pool
.workerChoiceStrategyContext
.getRequiredStatistics()
648 // We need to clean up the resources after our test
652 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a fixed pool', async () => {
653 const pool
= new FixedThreadPool(
655 './tests/worker-files/thread/testWorker.js',
656 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
658 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
659 const maxMultiplier
= 2
660 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
663 for (const workerNode
of pool
.workerNodes
) {
664 expect(workerNode
.tasksUsage
).toStrictEqual({
665 run
: max
* maxMultiplier
,
667 runTime
: expect
.any(Number
),
668 runTimeHistory
: expect
.any(CircularArray
),
669 avgRunTime
: expect
.any(Number
),
672 waitTimeHistory
: expect
.any(CircularArray
),
677 expect(workerNode
.tasksUsage
.avgRunTime
).toBeGreaterThanOrEqual(0)
680 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
681 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
682 ).defaultWorkerWeight
685 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
686 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
687 ).workerVirtualTaskRunTime
688 ).toBeGreaterThanOrEqual(0)
689 // We need to clean up the resources after our test
693 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a dynamic pool', async () => {
694 const pool
= new DynamicThreadPool(
697 './tests/worker-files/thread/testWorker.js',
698 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
700 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
701 const maxMultiplier
= 2
702 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
705 for (const workerNode
of pool
.workerNodes
) {
706 expect(workerNode
.tasksUsage
).toStrictEqual({
707 run
: max
* maxMultiplier
,
709 runTime
: expect
.any(Number
),
710 runTimeHistory
: expect
.any(CircularArray
),
711 avgRunTime
: expect
.any(Number
),
714 waitTimeHistory
: expect
.any(CircularArray
),
719 expect(workerNode
.tasksUsage
.avgRunTime
).toBeGreaterThanOrEqual(0)
722 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
723 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
724 ).defaultWorkerWeight
727 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
728 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
729 ).workerVirtualTaskRunTime
730 ).toBeGreaterThanOrEqual(0)
731 // We need to clean up the resources after our test
735 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a dynamic pool with median runtime statistic', async () => {
736 const pool
= new DynamicThreadPool(
739 './tests/worker-files/thread/testWorker.js',
741 workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
,
742 workerChoiceStrategyOptions
: {
747 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
748 const maxMultiplier
= 2
749 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
752 for (const workerNode
of pool
.workerNodes
) {
753 expect(workerNode
.tasksUsage
).toStrictEqual({
754 run
: max
* maxMultiplier
,
756 runTime
: expect
.any(Number
),
757 runTimeHistory
: expect
.any(CircularArray
),
759 medRunTime
: expect
.any(Number
),
761 waitTimeHistory
: expect
.any(CircularArray
),
766 expect(workerNode
.tasksUsage
.medRunTime
).toBeGreaterThanOrEqual(0)
769 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
770 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
771 ).defaultWorkerWeight
774 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
775 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
776 ).workerVirtualTaskRunTime
777 ).toBeGreaterThanOrEqual(0)
778 // We need to clean up the resources after our test
782 it('Verify WEIGHTED_ROUND_ROBIN strategy internals are resets after setting it', async () => {
783 const workerChoiceStrategy
= WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
784 let pool
= new FixedThreadPool(
786 './tests/worker-files/thread/testWorker.js'
789 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
791 ).currentWorkerNodeId
794 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
796 ).defaultWorkerWeight
799 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
801 ).workerVirtualTaskRunTime
803 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
805 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
806 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
807 ).currentWorkerNodeId
810 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
811 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
812 ).defaultWorkerWeight
815 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
817 ).workerVirtualTaskRunTime
820 pool
= new DynamicThreadPool(
823 './tests/worker-files/thread/testWorker.js'
826 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
828 ).currentWorkerNodeId
831 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
833 ).defaultWorkerWeight
836 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
838 ).workerVirtualTaskRunTime
840 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
842 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
843 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
844 ).currentWorkerNodeId
847 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
848 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
849 ).defaultWorkerWeight
852 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
854 ).workerVirtualTaskRunTime
856 // We need to clean up the resources after our test
860 it('Verify unknown strategy throw error', () => {
863 new DynamicThreadPool(
866 './tests/worker-files/thread/testWorker.js',
867 { workerChoiceStrategy
: 'UNKNOWN_STRATEGY' }
869 ).toThrowError("Invalid worker choice strategy 'UNKNOWN_STRATEGY'")