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
) {
80 for (const workerNodeKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
81 .get(workerChoiceStrategy
)
82 .workerLastVirtualTaskTimestamp
.keys()) {
84 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
85 .get(workerChoiceStrategy
)
86 .workerLastVirtualTaskTimestamp
.get(workerNodeKey
).start
89 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
90 .get(workerChoiceStrategy
)
91 .workerLastVirtualTaskTimestamp
.get(workerNodeKey
).end
95 workerChoiceStrategy
=== WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
98 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
100 ).currentWorkerNodeId
103 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
105 ).defaultWorkerWeight
107 for (const workerNodeKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
108 .get(workerChoiceStrategy
)
109 .workersTaskRunTime
.keys()) {
111 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
112 .get(workerChoiceStrategy
)
113 .workersTaskRunTime
.get(workerNodeKey
).weight
116 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
117 .get(workerChoiceStrategy
)
118 .workersTaskRunTime
.get(workerNodeKey
).runTime
126 it('Verify ROUND_ROBIN strategy default tasks usage statistics requirements', async () => {
127 const workerChoiceStrategy
= WorkerChoiceStrategies
.ROUND_ROBIN
128 let pool
= new FixedThreadPool(
130 './tests/worker-files/thread/testWorker.js',
131 { workerChoiceStrategy
}
134 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
137 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
140 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
143 pool
= new DynamicThreadPool(
146 './tests/worker-files/thread/testWorker.js',
147 { workerChoiceStrategy
}
150 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
153 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
156 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
158 // We need to clean up the resources after our test
162 it('Verify ROUND_ROBIN strategy can be run in a fixed pool', async () => {
163 const pool
= new FixedThreadPool(
165 './tests/worker-files/thread/testWorker.js',
166 { workerChoiceStrategy
: WorkerChoiceStrategies
.ROUND_ROBIN
}
168 // TODO: Create a better test to cover `RoundRobinWorkerChoiceStrategy#choose`
170 const maxMultiplier
= 2
171 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
172 promises
.push(pool
.execute())
174 await Promise
.all(promises
)
175 // We need to clean up the resources after our test
179 it('Verify ROUND_ROBIN strategy can be run in a dynamic pool', async () => {
180 const pool
= new DynamicThreadPool(
183 './tests/worker-files/thread/testWorker.js',
184 { workerChoiceStrategy
: WorkerChoiceStrategies
.ROUND_ROBIN
}
186 // TODO: Create a better test to cover `RoundRobinWorkerChoiceStrategy#choose`
188 const maxMultiplier
= 2
189 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
190 promises
.push(pool
.execute())
192 await Promise
.all(promises
)
193 // We need to clean up the resources after our test
197 it('Verify ROUND_ROBIN strategy runtime behavior', async () => {
198 const workerChoiceStrategy
= WorkerChoiceStrategies
.ROUND_ROBIN
199 let pool
= new FixedClusterPool(
201 './tests/worker-files/cluster/testWorker.js',
202 { workerChoiceStrategy
}
204 let results
= new Set()
205 for (let i
= 0; i
< max
; i
++) {
206 results
.add(pool
.chooseWorkerNode()[1].worker
.id
)
208 expect(results
.size
).toBe(max
)
210 pool
= new FixedThreadPool(
212 './tests/worker-files/thread/testWorker.js',
213 { workerChoiceStrategy
}
216 for (let i
= 0; i
< max
; i
++) {
217 results
.add(pool
.chooseWorkerNode()[1].worker
.threadId
)
219 expect(results
.size
).toBe(max
)
223 it('Verify ROUND_ROBIN strategy internals are resets after setting it', async () => {
224 const workerChoiceStrategy
= WorkerChoiceStrategies
.ROUND_ROBIN
225 let pool
= new FixedThreadPool(
227 './tests/worker-files/thread/testWorker.js',
228 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
231 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
235 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
237 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
238 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
242 pool
= new DynamicThreadPool(
245 './tests/worker-files/thread/testWorker.js',
246 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
249 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
253 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
255 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
256 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
259 // We need to clean up the resources after our test
263 it('Verify LESS_USED strategy default tasks usage statistics requirements', async () => {
264 const workerChoiceStrategy
= WorkerChoiceStrategies
.LESS_USED
265 let pool
= new FixedThreadPool(
267 './tests/worker-files/thread/testWorker.js',
268 { workerChoiceStrategy
}
271 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
274 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
277 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
280 pool
= new DynamicThreadPool(
283 './tests/worker-files/thread/testWorker.js',
284 { workerChoiceStrategy
}
287 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
290 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
293 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
295 // We need to clean up the resources after our test
299 it('Verify LESS_USED strategy can be run in a fixed pool', async () => {
300 const pool
= new FixedThreadPool(
302 './tests/worker-files/thread/testWorker.js',
303 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_USED
}
305 // TODO: Create a better test to cover `LessUsedWorkerChoiceStrategy#choose`
307 const maxMultiplier
= 2
308 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
309 promises
.push(pool
.execute())
311 await Promise
.all(promises
)
312 // We need to clean up the resources after our test
316 it('Verify LESS_USED strategy can be run in a dynamic pool', async () => {
317 const pool
= new DynamicThreadPool(
320 './tests/worker-files/thread/testWorker.js',
321 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_USED
}
323 // TODO: Create a better test to cover `LessUsedWorkerChoiceStrategy#choose`
325 const maxMultiplier
= 2
326 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
327 promises
.push(pool
.execute())
329 await Promise
.all(promises
)
330 // We need to clean up the resources after our test
334 it('Verify LESS_BUSY strategy default tasks usage statistics requirements', async () => {
335 const workerChoiceStrategy
= WorkerChoiceStrategies
.LESS_BUSY
336 let pool
= new FixedThreadPool(
338 './tests/worker-files/thread/testWorker.js',
339 { workerChoiceStrategy
}
342 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
345 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
348 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
351 pool
= new DynamicThreadPool(
354 './tests/worker-files/thread/testWorker.js',
355 { workerChoiceStrategy
}
358 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
361 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
364 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
366 // We need to clean up the resources after our test
370 it('Verify LESS_BUSY strategy can be run in a fixed pool', async () => {
371 const pool
= new FixedThreadPool(
373 './tests/worker-files/thread/testWorker.js',
374 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_BUSY
}
376 // TODO: Create a better test to cover `LessBusyWorkerChoiceStrategy#choose`
378 const maxMultiplier
= 2
379 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
380 promises
.push(pool
.execute())
382 await Promise
.all(promises
)
383 // We need to clean up the resources after our test
387 it('Verify LESS_BUSY strategy can be run in a dynamic pool', async () => {
388 const pool
= new DynamicThreadPool(
391 './tests/worker-files/thread/testWorker.js',
392 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_BUSY
}
394 // TODO: Create a better test to cover `LessBusyWorkerChoiceStrategy#choose`
396 const maxMultiplier
= 2
397 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
398 promises
.push(pool
.execute())
400 await Promise
.all(promises
)
401 // We need to clean up the resources after our test
405 it('Verify FAIR_SHARE strategy default tasks usage statistics requirements', async () => {
406 const workerChoiceStrategy
= WorkerChoiceStrategies
.FAIR_SHARE
407 let pool
= new FixedThreadPool(
409 './tests/worker-files/thread/testWorker.js',
410 { workerChoiceStrategy
}
413 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
416 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
419 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
422 pool
= new DynamicThreadPool(
425 './tests/worker-files/thread/testWorker.js',
426 { workerChoiceStrategy
}
429 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
432 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
435 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
437 // We need to clean up the resources after our test
441 it('Verify FAIR_SHARE strategy can be run in a fixed pool', async () => {
442 const pool
= new FixedThreadPool(
444 './tests/worker-files/thread/testWorker.js',
445 { workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
}
447 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
449 const maxMultiplier
= 2
450 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
451 promises
.push(pool
.execute())
453 await Promise
.all(promises
)
455 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
456 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
457 ).workerLastVirtualTaskTimestamp
.size
458 ).toBe(pool
.workerNodes
.length
)
459 // We need to clean up the resources after our test
463 it('Verify FAIR_SHARE strategy can be run in a dynamic pool', async () => {
464 const pool
= new DynamicThreadPool(
467 './tests/worker-files/thread/testWorker.js',
468 { workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
}
470 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
472 const maxMultiplier
= 2
473 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
474 promises
.push(pool
.execute())
476 await Promise
.all(promises
)
477 // if (process.platform !== 'win32') {
479 // pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
480 // pool.workerChoiceStrategyContext.workerChoiceStrategy
481 // ).workerLastVirtualTaskTimestamp.size
482 // ).toBe(pool.workerNodes.length)
484 // We need to clean up the resources after our test
488 it('Verify FAIR_SHARE strategy can be run in a dynamic pool with median run time statistic', async () => {
489 const pool
= new DynamicThreadPool(
492 './tests/worker-files/thread/testWorker.js',
494 workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
,
495 workerChoiceStrategyOptions
: {
500 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
502 const maxMultiplier
= 2
503 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
504 promises
.push(pool
.execute())
506 await Promise
.all(promises
)
507 for (const workerNode
of pool
.workerNodes
) {
508 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
509 expect(workerNode
.tasksUsage
.avgRunTime
).toBe(0)
510 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
511 expect(workerNode
.tasksUsage
.medRunTime
).toBeGreaterThan(0)
513 // if (process.platform !== 'win32') {
515 // pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
516 // pool.workerChoiceStrategyContext.workerChoiceStrategy
517 // ).workerLastVirtualTaskTimestamp.size
518 // ).toBe(pool.workerNodes.length)
520 // We need to clean up the resources after our test
524 it('Verify FAIR_SHARE strategy internals are resets after setting it', async () => {
525 const workerChoiceStrategy
= WorkerChoiceStrategies
.FAIR_SHARE
526 let pool
= new FixedThreadPool(
528 './tests/worker-files/thread/testWorker.js'
531 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
533 ).workerLastVirtualTaskTimestamp
535 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
536 for (const workerNodeKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
537 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
538 .workerLastVirtualTaskTimestamp
.keys()) {
540 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
541 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
542 .workerLastVirtualTaskTimestamp
.get(workerNodeKey
).start
545 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
546 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
547 .workerLastVirtualTaskTimestamp
.get(workerNodeKey
).end
551 pool
= new DynamicThreadPool(
554 './tests/worker-files/thread/testWorker.js'
557 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
559 ).workerLastVirtualTaskTimestamp
561 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
562 for (const workerNodeKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
563 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
564 .workerLastVirtualTaskTimestamp
.keys()) {
566 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
567 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
568 .workerLastVirtualTaskTimestamp
.get(workerNodeKey
).start
571 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
572 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
573 .workerLastVirtualTaskTimestamp
.get(workerNodeKey
).end
576 // We need to clean up the resources after our test
580 it('Verify WEIGHTED_ROUND_ROBIN strategy default tasks usage statistics requirements', async () => {
581 const workerChoiceStrategy
= WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
582 let pool
= new FixedThreadPool(
584 './tests/worker-files/thread/testWorker.js',
585 { workerChoiceStrategy
}
588 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
591 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
594 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
597 pool
= new DynamicThreadPool(
600 './tests/worker-files/thread/testWorker.js',
601 { workerChoiceStrategy
}
604 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
607 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
610 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
612 // We need to clean up the resources after our test
616 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a fixed pool', async () => {
617 const pool
= new FixedThreadPool(
619 './tests/worker-files/thread/testWorker.js',
620 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
622 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
624 const maxMultiplier
= 2
625 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
626 promises
.push(pool
.execute())
628 await Promise
.all(promises
)
630 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
631 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
632 ).workersTaskRunTime
.size
633 ).toBe(pool
.workerNodes
.length
)
634 // We need to clean up the resources after our test
638 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a dynamic pool', async () => {
639 const pool
= new DynamicThreadPool(
642 './tests/worker-files/thread/testWorker.js',
643 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
645 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
647 const maxMultiplier
=
648 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
649 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
650 ).defaultWorkerWeight
* 50
651 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
652 promises
.push(pool
.execute())
654 await Promise
.all(promises
)
655 if (process
.platform
!== 'win32') {
657 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
658 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
659 ).workersTaskRunTime
.size
660 ).toBe(pool
.workerNodes
.length
)
662 // We need to clean up the resources after our test
666 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a dynamic pool with median run time statistic', async () => {
667 const pool
= new DynamicThreadPool(
670 './tests/worker-files/thread/testWorker.js',
672 workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
,
673 workerChoiceStrategyOptions
: {
678 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
680 const maxMultiplier
= 2
681 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
682 promises
.push(pool
.execute())
684 await Promise
.all(promises
)
685 for (const workerNode
of pool
.workerNodes
) {
686 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
687 expect(workerNode
.tasksUsage
.avgRunTime
).toBe(0)
688 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
689 expect(workerNode
.tasksUsage
.medRunTime
).toBeGreaterThan(0)
691 // if (process.platform !== 'win32') {
693 // pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
694 // pool.workerChoiceStrategyContext.workerChoiceStrategy
695 // ).workersTaskRunTime.size
696 // ).toBe(pool.workerNodes.length)
698 // We need to clean up the resources after our test
702 it('Verify WEIGHTED_ROUND_ROBIN strategy internals are resets after setting it', async () => {
703 const workerChoiceStrategy
= WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
704 let pool
= new FixedThreadPool(
706 './tests/worker-files/thread/testWorker.js'
709 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
711 ).currentWorkerNodeId
714 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
716 ).defaultWorkerWeight
719 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
723 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
725 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
726 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
727 ).currentWorkerNodeId
730 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
731 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
732 ).defaultWorkerWeight
734 for (const workerNodeKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
735 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
736 .workersTaskRunTime
.keys()) {
738 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
739 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
740 .workersTaskRunTime
.get(workerNodeKey
).runTime
744 pool
= new DynamicThreadPool(
747 './tests/worker-files/thread/testWorker.js'
750 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
752 ).currentWorkerNodeId
755 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
757 ).defaultWorkerWeight
760 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
764 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
766 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
767 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
768 ).currentWorkerNodeId
771 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
772 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
773 ).defaultWorkerWeight
775 for (const workerNodeKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
776 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
777 .workersTaskRunTime
.keys()) {
779 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
780 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
781 .workersTaskRunTime
.get(workerNodeKey
).runTime
784 // We need to clean up the resources after our test
788 it('Verify unknown strategy throw error', () => {
791 new DynamicThreadPool(
794 './tests/worker-files/thread/testWorker.js',
795 { workerChoiceStrategy
: 'UNKNOWN_STRATEGY' }
797 ).toThrowError("Invalid worker choice strategy 'UNKNOWN_STRATEGY'")