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 ).workersVirtualTaskEndTimestamp
84 ).toBeInstanceOf(Array
)
86 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
88 ).workersVirtualTaskEndTimestamp
.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`
156 const maxMultiplier
= 2
157 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
160 // We need to clean up the resources after our test
164 it('Verify ROUND_ROBIN strategy can be run in a dynamic pool', async () => {
165 const pool
= new DynamicThreadPool(
168 './tests/worker-files/thread/testWorker.js',
169 { workerChoiceStrategy
: WorkerChoiceStrategies
.ROUND_ROBIN
}
171 // TODO: Create a better test to cover `RoundRobinWorkerChoiceStrategy#choose`
172 const maxMultiplier
= 2
173 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
176 // We need to clean up the resources after our test
180 it('Verify ROUND_ROBIN strategy runtime behavior', async () => {
181 const workerChoiceStrategy
= WorkerChoiceStrategies
.ROUND_ROBIN
182 let pool
= new FixedClusterPool(
184 './tests/worker-files/cluster/testWorker.js',
185 { workerChoiceStrategy
}
187 let results
= new Set()
188 for (let i
= 0; i
< max
; i
++) {
189 results
.add(pool
.chooseWorkerNode()[1].worker
.id
)
191 expect(results
.size
).toBe(max
)
193 pool
= new FixedThreadPool(
195 './tests/worker-files/thread/testWorker.js',
196 { workerChoiceStrategy
}
199 for (let i
= 0; i
< max
; i
++) {
200 results
.add(pool
.chooseWorkerNode()[1].worker
.threadId
)
202 expect(results
.size
).toBe(max
)
206 it('Verify ROUND_ROBIN strategy internals are resets after setting it', async () => {
207 const workerChoiceStrategy
= WorkerChoiceStrategies
.ROUND_ROBIN
208 let pool
= new FixedThreadPool(
210 './tests/worker-files/thread/testWorker.js',
211 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
214 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
218 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
220 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
221 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
225 pool
= new DynamicThreadPool(
228 './tests/worker-files/thread/testWorker.js',
229 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
232 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
236 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
238 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
239 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
242 // We need to clean up the resources after our test
246 it('Verify LESS_USED strategy default tasks usage statistics requirements', async () => {
247 const workerChoiceStrategy
= WorkerChoiceStrategies
.LESS_USED
248 let pool
= new FixedThreadPool(
250 './tests/worker-files/thread/testWorker.js',
251 { workerChoiceStrategy
}
254 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
257 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
260 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
263 pool
= new DynamicThreadPool(
266 './tests/worker-files/thread/testWorker.js',
267 { workerChoiceStrategy
}
270 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
273 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
276 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
278 // We need to clean up the resources after our test
282 it('Verify LESS_USED strategy can be run in a fixed pool', async () => {
283 const pool
= new FixedThreadPool(
285 './tests/worker-files/thread/testWorker.js',
286 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_USED
}
288 // TODO: Create a better test to cover `LessUsedWorkerChoiceStrategy#choose`
289 const maxMultiplier
= 2
290 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
293 // We need to clean up the resources after our test
297 it('Verify LESS_USED strategy can be run in a dynamic pool', async () => {
298 const pool
= new DynamicThreadPool(
301 './tests/worker-files/thread/testWorker.js',
302 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_USED
}
304 // TODO: Create a better test to cover `LessUsedWorkerChoiceStrategy#choose`
305 const maxMultiplier
= 2
306 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
309 // We need to clean up the resources after our test
313 it('Verify LESS_BUSY strategy default tasks usage statistics requirements', async () => {
314 const workerChoiceStrategy
= WorkerChoiceStrategies
.LESS_BUSY
315 let pool
= new FixedThreadPool(
317 './tests/worker-files/thread/testWorker.js',
318 { workerChoiceStrategy
}
321 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
324 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
327 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
330 pool
= new DynamicThreadPool(
333 './tests/worker-files/thread/testWorker.js',
334 { workerChoiceStrategy
}
337 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
340 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
343 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
345 // We need to clean up the resources after our test
349 it('Verify LESS_BUSY strategy can be run in a fixed pool', async () => {
350 const pool
= new FixedThreadPool(
352 './tests/worker-files/thread/testWorker.js',
353 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_BUSY
}
355 // TODO: Create a better test to cover `LessBusyWorkerChoiceStrategy#choose`
356 const maxMultiplier
= 2
357 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
360 // We need to clean up the resources after our test
364 it('Verify LESS_BUSY strategy can be run in a dynamic pool', async () => {
365 const pool
= new DynamicThreadPool(
368 './tests/worker-files/thread/testWorker.js',
369 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_BUSY
}
371 // TODO: Create a better test to cover `LessBusyWorkerChoiceStrategy#choose`
372 const maxMultiplier
= 2
373 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
376 // We need to clean up the resources after our test
380 it('Verify FAIR_SHARE strategy default tasks usage statistics requirements', async () => {
381 const workerChoiceStrategy
= WorkerChoiceStrategies
.FAIR_SHARE
382 let pool
= new FixedThreadPool(
384 './tests/worker-files/thread/testWorker.js',
385 { workerChoiceStrategy
}
388 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
391 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
394 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
397 pool
= new DynamicThreadPool(
400 './tests/worker-files/thread/testWorker.js',
401 { workerChoiceStrategy
}
404 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
407 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
410 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
412 // We need to clean up the resources after our test
416 it('Verify FAIR_SHARE strategy can be run in a fixed pool', async () => {
417 const pool
= new FixedThreadPool(
419 './tests/worker-files/thread/testWorker.js',
420 { workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
}
422 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
423 const maxMultiplier
= 2
424 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
427 for (const workerNode
of pool
.workerNodes
) {
428 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
429 expect(workerNode
.tasksUsage
.avgRunTime
).toBeGreaterThanOrEqual(0)
430 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
431 expect(workerNode
.tasksUsage
.medRunTime
).toBe(0)
434 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
435 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
436 ).workersVirtualTaskEndTimestamp
.length
437 ).toBe(pool
.workerNodes
.length
)
438 // We need to clean up the resources after our test
442 it('Verify FAIR_SHARE strategy can be run in a dynamic pool', async () => {
443 const pool
= new DynamicThreadPool(
446 './tests/worker-files/thread/testWorker.js',
447 { workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
}
449 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
450 const maxMultiplier
= 2
451 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
454 for (const workerNode
of pool
.workerNodes
) {
455 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
456 expect(workerNode
.tasksUsage
.avgRunTime
).toBeGreaterThanOrEqual(0)
457 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
458 expect(workerNode
.tasksUsage
.medRunTime
).toBe(0)
461 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
462 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
463 ).workersVirtualTaskEndTimestamp
.length
464 ).toBe(pool
.workerNodes
.length
)
465 // We need to clean up the resources after our test
469 it('Verify FAIR_SHARE strategy can be run in a dynamic pool with median run time statistic', async () => {
470 const pool
= new DynamicThreadPool(
473 './tests/worker-files/thread/testWorker.js',
475 workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
,
476 workerChoiceStrategyOptions
: {
481 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
482 const maxMultiplier
= 2
483 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
486 for (const workerNode
of pool
.workerNodes
) {
487 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
488 expect(workerNode
.tasksUsage
.avgRunTime
).toBe(0)
489 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
490 expect(workerNode
.tasksUsage
.medRunTime
).toBeGreaterThanOrEqual(0)
493 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
494 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
495 ).workersVirtualTaskEndTimestamp
.length
496 ).toBe(pool
.workerNodes
.length
)
497 // We need to clean up the resources after our test
501 it('Verify FAIR_SHARE strategy internals are resets after setting it', async () => {
502 const workerChoiceStrategy
= WorkerChoiceStrategies
.FAIR_SHARE
503 let pool
= new FixedThreadPool(
505 './tests/worker-files/thread/testWorker.js'
508 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
510 ).workersVirtualTaskEndTimestamp
511 ).toBeInstanceOf(Array
)
513 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
515 ).workersVirtualTaskEndTimestamp
.length
517 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
519 ).workersVirtualTaskEndTimestamp
[0] = performance
.now()
521 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
523 ).workersVirtualTaskEndTimestamp
.length
525 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
527 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
529 ).workersVirtualTaskEndTimestamp
530 ).toBeInstanceOf(Array
)
532 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
534 ).workersVirtualTaskEndTimestamp
.length
537 pool
= new DynamicThreadPool(
540 './tests/worker-files/thread/testWorker.js'
543 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
545 ).workersVirtualTaskEndTimestamp
546 ).toBeInstanceOf(Array
)
548 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
550 ).workersVirtualTaskEndTimestamp
.length
552 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
554 ).workersVirtualTaskEndTimestamp
[0] = performance
.now()
556 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
558 ).workersVirtualTaskEndTimestamp
.length
560 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
562 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
564 ).workersVirtualTaskEndTimestamp
565 ).toBeInstanceOf(Array
)
567 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
569 ).workersVirtualTaskEndTimestamp
.length
571 // We need to clean up the resources after our test
575 it('Verify WEIGHTED_ROUND_ROBIN strategy default tasks usage statistics requirements', async () => {
576 const workerChoiceStrategy
= WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
577 let pool
= new FixedThreadPool(
579 './tests/worker-files/thread/testWorker.js',
580 { workerChoiceStrategy
}
583 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
586 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
589 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
592 pool
= new DynamicThreadPool(
595 './tests/worker-files/thread/testWorker.js',
596 { workerChoiceStrategy
}
599 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
602 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
605 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
607 // We need to clean up the resources after our test
611 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a fixed pool', async () => {
612 const pool
= new FixedThreadPool(
614 './tests/worker-files/thread/testWorker.js',
615 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
617 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
618 const maxMultiplier
= 2
619 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
622 for (const workerNode
of pool
.workerNodes
) {
623 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
624 expect(workerNode
.tasksUsage
.avgRunTime
).toBeGreaterThanOrEqual(0)
625 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
626 expect(workerNode
.tasksUsage
.medRunTime
).toBe(0)
629 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
630 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
631 ).defaultWorkerWeight
634 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
635 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
636 ).workerVirtualTaskRunTime
637 ).toBeGreaterThanOrEqual(0)
638 // We need to clean up the resources after our test
642 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a dynamic pool', async () => {
643 const pool
= new DynamicThreadPool(
646 './tests/worker-files/thread/testWorker.js',
647 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
649 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
650 const maxMultiplier
= 2
651 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
654 for (const workerNode
of pool
.workerNodes
) {
655 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
656 expect(workerNode
.tasksUsage
.avgRunTime
).toBeGreaterThanOrEqual(0)
657 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
658 expect(workerNode
.tasksUsage
.medRunTime
).toBe(0)
661 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
662 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
663 ).defaultWorkerWeight
666 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
667 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
668 ).workerVirtualTaskRunTime
669 ).toBeGreaterThanOrEqual(0)
670 // We need to clean up the resources after our test
674 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a dynamic pool with median run time statistic', async () => {
675 const pool
= new DynamicThreadPool(
678 './tests/worker-files/thread/testWorker.js',
680 workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
,
681 workerChoiceStrategyOptions
: {
686 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
687 const maxMultiplier
= 2
688 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
691 for (const workerNode
of pool
.workerNodes
) {
692 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
693 expect(workerNode
.tasksUsage
.avgRunTime
).toBe(0)
694 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
695 expect(workerNode
.tasksUsage
.medRunTime
).toBeGreaterThanOrEqual(0)
698 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
699 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
700 ).defaultWorkerWeight
703 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
704 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
705 ).workerVirtualTaskRunTime
706 ).toBeGreaterThanOrEqual(0)
707 // We need to clean up the resources after our test
711 it('Verify WEIGHTED_ROUND_ROBIN strategy internals are resets after setting it', async () => {
712 const workerChoiceStrategy
= WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
713 let pool
= new FixedThreadPool(
715 './tests/worker-files/thread/testWorker.js'
718 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
720 ).currentWorkerNodeId
723 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
725 ).defaultWorkerWeight
728 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
730 ).workerVirtualTaskRunTime
732 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
734 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
735 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
736 ).currentWorkerNodeId
739 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
740 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
741 ).defaultWorkerWeight
744 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
746 ).workerVirtualTaskRunTime
749 pool
= new DynamicThreadPool(
752 './tests/worker-files/thread/testWorker.js'
755 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
757 ).currentWorkerNodeId
760 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
762 ).defaultWorkerWeight
765 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
767 ).workerVirtualTaskRunTime
769 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
771 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
772 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
773 ).currentWorkerNodeId
776 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
777 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
778 ).defaultWorkerWeight
781 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
783 ).workerVirtualTaskRunTime
785 // We need to clean up the resources after our test
789 it('Verify unknown strategy throw error', () => {
792 new DynamicThreadPool(
795 './tests/worker-files/thread/testWorker.js',
796 { workerChoiceStrategy
: 'UNKNOWN_STRATEGY' }
798 ).toThrowError("Invalid worker choice strategy 'UNKNOWN_STRATEGY'")