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
.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 available strategies are taken at pool creation', async () => {
37 for (const workerChoiceStrategy
of Object
.values(WorkerChoiceStrategies
)) {
38 const pool
= new FixedThreadPool(
40 './tests/worker-files/thread/testWorker.js',
41 { workerChoiceStrategy
}
43 expect(pool
.opts
.workerChoiceStrategy
).toBe(workerChoiceStrategy
)
44 expect(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
).toBe(
51 it('Verify available strategies can be set after pool creation', async () => {
52 for (const workerChoiceStrategy
of Object
.values(WorkerChoiceStrategies
)) {
53 const pool
= new DynamicThreadPool(
56 './tests/worker-files/thread/testWorker.js'
58 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
59 expect(pool
.opts
.workerChoiceStrategy
).toBe(workerChoiceStrategy
)
60 expect(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
).toBe(
67 it('Verify available strategies default internals at pool creation', async () => {
68 const pool
= new FixedThreadPool(
70 './tests/worker-files/thread/testWorker.js'
72 for (const workerChoiceStrategy
of Object
.values(WorkerChoiceStrategies
)) {
73 if (workerChoiceStrategy
=== WorkerChoiceStrategies
.ROUND_ROBIN
) {
75 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
79 } else if (workerChoiceStrategy
=== WorkerChoiceStrategies
.FAIR_SHARE
) {
81 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
83 ).workersVirtualTaskTimestamp
84 ).toBeInstanceOf(Array
)
86 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
88 ).workersVirtualTaskTimestamp
.length
91 workerChoiceStrategy
=== WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
94 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
99 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
101 ).defaultWorkerWeight
104 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
106 ).workerVirtualTaskRunTime
113 it('Verify ROUND_ROBIN strategy default tasks usage statistics requirements', async () => {
114 const workerChoiceStrategy
= WorkerChoiceStrategies
.ROUND_ROBIN
115 let pool
= new FixedThreadPool(
117 './tests/worker-files/thread/testWorker.js',
118 { workerChoiceStrategy
}
121 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
124 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
127 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
130 pool
= new DynamicThreadPool(
133 './tests/worker-files/thread/testWorker.js',
134 { workerChoiceStrategy
}
137 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
140 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
143 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
145 // We need to clean up the resources after our test
149 it('Verify ROUND_ROBIN strategy can be run in a fixed pool', async () => {
150 const pool
= new FixedThreadPool(
152 './tests/worker-files/thread/testWorker.js',
153 { workerChoiceStrategy
: WorkerChoiceStrategies
.ROUND_ROBIN
}
155 // TODO: Create a better test to cover `RoundRobinWorkerChoiceStrategy#choose`
157 const maxMultiplier
= 2
158 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
159 promises
.push(pool
.execute())
161 await Promise
.all(promises
)
162 // We need to clean up the resources after our test
166 it('Verify ROUND_ROBIN strategy can be run in a dynamic pool', async () => {
167 const pool
= new DynamicThreadPool(
170 './tests/worker-files/thread/testWorker.js',
171 { workerChoiceStrategy
: WorkerChoiceStrategies
.ROUND_ROBIN
}
173 // TODO: Create a better test to cover `RoundRobinWorkerChoiceStrategy#choose`
175 const maxMultiplier
= 2
176 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
177 promises
.push(pool
.execute())
179 await Promise
.all(promises
)
180 // We need to clean up the resources after our test
184 it('Verify ROUND_ROBIN strategy runtime behavior', async () => {
185 const workerChoiceStrategy
= WorkerChoiceStrategies
.ROUND_ROBIN
186 let pool
= new FixedClusterPool(
188 './tests/worker-files/cluster/testWorker.js',
189 { workerChoiceStrategy
}
191 let results
= new Set()
192 for (let i
= 0; i
< max
; i
++) {
193 results
.add(pool
.chooseWorkerNode()[1].worker
.id
)
195 expect(results
.size
).toBe(max
)
197 pool
= new FixedThreadPool(
199 './tests/worker-files/thread/testWorker.js',
200 { workerChoiceStrategy
}
203 for (let i
= 0; i
< max
; i
++) {
204 results
.add(pool
.chooseWorkerNode()[1].worker
.threadId
)
206 expect(results
.size
).toBe(max
)
210 it('Verify ROUND_ROBIN strategy internals are resets after setting it', async () => {
211 const workerChoiceStrategy
= WorkerChoiceStrategies
.ROUND_ROBIN
212 let pool
= new FixedThreadPool(
214 './tests/worker-files/thread/testWorker.js',
215 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
218 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
222 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
224 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
225 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
229 pool
= new DynamicThreadPool(
232 './tests/worker-files/thread/testWorker.js',
233 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
236 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
240 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
242 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
243 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
246 // We need to clean up the resources after our test
250 it('Verify LESS_USED strategy default tasks usage statistics requirements', async () => {
251 const workerChoiceStrategy
= WorkerChoiceStrategies
.LESS_USED
252 let pool
= new FixedThreadPool(
254 './tests/worker-files/thread/testWorker.js',
255 { workerChoiceStrategy
}
258 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
261 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
264 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
267 pool
= new DynamicThreadPool(
270 './tests/worker-files/thread/testWorker.js',
271 { workerChoiceStrategy
}
274 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
277 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
280 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
282 // We need to clean up the resources after our test
286 it('Verify LESS_USED strategy can be run in a fixed pool', async () => {
287 const pool
= new FixedThreadPool(
289 './tests/worker-files/thread/testWorker.js',
290 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_USED
}
292 // TODO: Create a better test to cover `LessUsedWorkerChoiceStrategy#choose`
294 const maxMultiplier
= 2
295 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
296 promises
.push(pool
.execute())
298 await Promise
.all(promises
)
299 // We need to clean up the resources after our test
303 it('Verify LESS_USED strategy can be run in a dynamic pool', async () => {
304 const pool
= new DynamicThreadPool(
307 './tests/worker-files/thread/testWorker.js',
308 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_USED
}
310 // TODO: Create a better test to cover `LessUsedWorkerChoiceStrategy#choose`
312 const maxMultiplier
= 2
313 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
314 promises
.push(pool
.execute())
316 await Promise
.all(promises
)
317 // We need to clean up the resources after our test
321 it('Verify LESS_BUSY strategy default tasks usage statistics requirements', async () => {
322 const workerChoiceStrategy
= WorkerChoiceStrategies
.LESS_BUSY
323 let pool
= new FixedThreadPool(
325 './tests/worker-files/thread/testWorker.js',
326 { workerChoiceStrategy
}
329 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
332 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
335 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
338 pool
= new DynamicThreadPool(
341 './tests/worker-files/thread/testWorker.js',
342 { workerChoiceStrategy
}
345 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
348 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
351 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
353 // We need to clean up the resources after our test
357 it('Verify LESS_BUSY strategy can be run in a fixed pool', async () => {
358 const pool
= new FixedThreadPool(
360 './tests/worker-files/thread/testWorker.js',
361 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_BUSY
}
363 // TODO: Create a better test to cover `LessBusyWorkerChoiceStrategy#choose`
365 const maxMultiplier
= 2
366 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
367 promises
.push(pool
.execute())
369 await Promise
.all(promises
)
370 // We need to clean up the resources after our test
374 it('Verify LESS_BUSY strategy can be run in a dynamic pool', async () => {
375 const pool
= new DynamicThreadPool(
378 './tests/worker-files/thread/testWorker.js',
379 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_BUSY
}
381 // TODO: Create a better test to cover `LessBusyWorkerChoiceStrategy#choose`
383 const maxMultiplier
= 2
384 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
385 promises
.push(pool
.execute())
387 await Promise
.all(promises
)
388 // We need to clean up the resources after our test
392 it('Verify FAIR_SHARE strategy default tasks usage statistics requirements', async () => {
393 const workerChoiceStrategy
= WorkerChoiceStrategies
.FAIR_SHARE
394 let pool
= new FixedThreadPool(
396 './tests/worker-files/thread/testWorker.js',
397 { workerChoiceStrategy
}
400 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
403 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
406 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
409 pool
= new DynamicThreadPool(
412 './tests/worker-files/thread/testWorker.js',
413 { workerChoiceStrategy
}
416 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
419 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
422 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
424 // We need to clean up the resources after our test
428 it('Verify FAIR_SHARE strategy can be run in a fixed pool', async () => {
429 const pool
= new FixedThreadPool(
431 './tests/worker-files/thread/testWorker.js',
432 { workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
}
434 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
436 const maxMultiplier
= 2
437 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
438 promises
.push(pool
.execute())
440 await Promise
.all(promises
)
441 for (const workerNode
of pool
.workerNodes
) {
442 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
443 expect(workerNode
.tasksUsage
.avgRunTime
).toBeGreaterThanOrEqual(0)
444 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
445 expect(workerNode
.tasksUsage
.medRunTime
).toBe(0)
448 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
449 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
450 ).workersVirtualTaskTimestamp
.length
451 ).toBe(pool
.workerNodes
.length
)
452 // We need to clean up the resources after our test
456 it('Verify FAIR_SHARE strategy can be run in a dynamic pool', async () => {
457 const pool
= new DynamicThreadPool(
460 './tests/worker-files/thread/testWorker.js',
461 { workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
}
463 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
465 const maxMultiplier
= 2
466 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
467 promises
.push(pool
.execute())
469 await Promise
.all(promises
)
470 for (const workerNode
of pool
.workerNodes
) {
471 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
472 expect(workerNode
.tasksUsage
.avgRunTime
).toBeGreaterThanOrEqual(0)
473 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
474 expect(workerNode
.tasksUsage
.medRunTime
).toBe(0)
477 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
478 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
479 ).workersVirtualTaskTimestamp
.length
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 with median run time statistic', async () => {
486 const pool
= new DynamicThreadPool(
489 './tests/worker-files/thread/testWorker.js',
491 workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
,
492 workerChoiceStrategyOptions
: {
497 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
499 const maxMultiplier
= 2
500 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
501 promises
.push(pool
.execute())
503 await Promise
.all(promises
)
504 for (const workerNode
of pool
.workerNodes
) {
505 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
506 expect(workerNode
.tasksUsage
.avgRunTime
).toBe(0)
507 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
508 expect(workerNode
.tasksUsage
.medRunTime
).toBeGreaterThanOrEqual(0)
511 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
512 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
513 ).workersVirtualTaskTimestamp
.length
514 ).toBe(pool
.workerNodes
.length
)
515 // We need to clean up the resources after our test
519 it('Verify FAIR_SHARE strategy internals are resets after setting it', async () => {
520 const workerChoiceStrategy
= WorkerChoiceStrategies
.FAIR_SHARE
521 let pool
= new FixedThreadPool(
523 './tests/worker-files/thread/testWorker.js'
526 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
528 ).workersVirtualTaskTimestamp
529 ).toBeInstanceOf(Array
)
531 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
533 ).workersVirtualTaskTimestamp
.length
535 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
537 ).workersVirtualTaskTimestamp
[0] = 0
539 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
541 ).workersVirtualTaskTimestamp
.length
543 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
545 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
547 ).workersVirtualTaskTimestamp
548 ).toBeInstanceOf(Array
)
550 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
552 ).workersVirtualTaskTimestamp
.length
555 pool
= new DynamicThreadPool(
558 './tests/worker-files/thread/testWorker.js'
561 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
563 ).workersVirtualTaskTimestamp
564 ).toBeInstanceOf(Array
)
566 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
568 ).workersVirtualTaskTimestamp
.length
570 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
572 ).workersVirtualTaskTimestamp
[0] = 0
574 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
576 ).workersVirtualTaskTimestamp
.length
578 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
580 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
582 ).workersVirtualTaskTimestamp
583 ).toBeInstanceOf(Array
)
585 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
587 ).workersVirtualTaskTimestamp
.length
589 // We need to clean up the resources after our test
593 it('Verify WEIGHTED_ROUND_ROBIN strategy default tasks usage statistics requirements', async () => {
594 const workerChoiceStrategy
= WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
595 let pool
= new FixedThreadPool(
597 './tests/worker-files/thread/testWorker.js',
598 { workerChoiceStrategy
}
601 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
604 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
607 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
610 pool
= new DynamicThreadPool(
613 './tests/worker-files/thread/testWorker.js',
614 { workerChoiceStrategy
}
617 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
620 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
623 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
625 // We need to clean up the resources after our test
629 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a fixed pool', async () => {
630 const pool
= new FixedThreadPool(
632 './tests/worker-files/thread/testWorker.js',
633 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
635 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
637 const maxMultiplier
= 2
638 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
639 promises
.push(pool
.execute())
641 await Promise
.all(promises
)
642 for (const workerNode
of pool
.workerNodes
) {
643 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
644 expect(workerNode
.tasksUsage
.avgRunTime
).toBeGreaterThanOrEqual(0)
645 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
646 expect(workerNode
.tasksUsage
.medRunTime
).toBe(0)
649 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
650 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
651 ).defaultWorkerWeight
654 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
655 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
656 ).workerVirtualTaskRunTime
657 ).toBeGreaterThanOrEqual(0)
658 // We need to clean up the resources after our test
662 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a dynamic pool', async () => {
663 const pool
= new DynamicThreadPool(
666 './tests/worker-files/thread/testWorker.js',
667 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
669 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
671 const maxMultiplier
= 2
672 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
673 promises
.push(pool
.execute())
675 await Promise
.all(promises
)
676 for (const workerNode
of pool
.workerNodes
) {
677 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
678 expect(workerNode
.tasksUsage
.avgRunTime
).toBeGreaterThanOrEqual(0)
679 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
680 expect(workerNode
.tasksUsage
.medRunTime
).toBe(0)
683 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
684 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
685 ).defaultWorkerWeight
688 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
689 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
690 ).workerVirtualTaskRunTime
691 ).toBeGreaterThanOrEqual(0)
692 // We need to clean up the resources after our test
696 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a dynamic pool with median run time statistic', async () => {
697 const pool
= new DynamicThreadPool(
700 './tests/worker-files/thread/testWorker.js',
702 workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
,
703 workerChoiceStrategyOptions
: {
708 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
710 const maxMultiplier
= 2
711 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
712 promises
.push(pool
.execute())
714 await Promise
.all(promises
)
715 for (const workerNode
of pool
.workerNodes
) {
716 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
717 expect(workerNode
.tasksUsage
.avgRunTime
).toBe(0)
718 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
719 expect(workerNode
.tasksUsage
.medRunTime
).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 internals are resets after setting it', async () => {
736 const workerChoiceStrategy
= WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
737 let pool
= new FixedThreadPool(
739 './tests/worker-files/thread/testWorker.js'
742 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
744 ).currentWorkerNodeId
747 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
749 ).defaultWorkerWeight
752 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
754 ).workerVirtualTaskRunTime
756 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
758 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
759 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
760 ).currentWorkerNodeId
763 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
764 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
765 ).defaultWorkerWeight
768 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
770 ).workerVirtualTaskRunTime
773 pool
= new DynamicThreadPool(
776 './tests/worker-files/thread/testWorker.js'
779 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
781 ).currentWorkerNodeId
784 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
786 ).defaultWorkerWeight
789 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
791 ).workerVirtualTaskRunTime
793 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
795 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
796 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
797 ).currentWorkerNodeId
800 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
801 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
802 ).defaultWorkerWeight
805 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
807 ).workerVirtualTaskRunTime
809 // We need to clean up the resources after our test
813 it('Verify unknown strategy throw error', () => {
816 new DynamicThreadPool(
819 './tests/worker-files/thread/testWorker.js',
820 { workerChoiceStrategy
: 'UNKNOWN_STRATEGY' }
822 ).toThrowError("Invalid worker choice strategy 'UNKNOWN_STRATEGY'")