1 const { expect
} = require('expect')
3 WorkerChoiceStrategies
,
7 } = require('../../../lib/index')
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 for (let i
= 0; i
< max
* 2; i
++) {
171 promises
.push(pool
.execute())
173 await Promise
.all(promises
)
174 // We need to clean up the resources after our test
178 it('Verify ROUND_ROBIN strategy can be run in a dynamic pool', async () => {
179 const pool
= new DynamicThreadPool(
182 './tests/worker-files/thread/testWorker.js',
183 { workerChoiceStrategy
: WorkerChoiceStrategies
.ROUND_ROBIN
}
185 // TODO: Create a better test to cover `RoundRobinWorkerChoiceStrategy#choose`
187 for (let i
= 0; i
< max
* 2; i
++) {
188 promises
.push(pool
.execute())
190 await Promise
.all(promises
)
191 // We need to clean up the resources after our test
195 it('Verify ROUND_ROBIN strategy runtime behavior', async () => {
196 const workerChoiceStrategy
= WorkerChoiceStrategies
.ROUND_ROBIN
197 let pool
= new FixedClusterPool(
199 './tests/worker-files/cluster/testWorker.js',
200 { workerChoiceStrategy
}
202 let results
= new Set()
203 for (let i
= 0; i
< max
; i
++) {
204 results
.add(pool
.chooseWorkerNode()[1].worker
.id
)
206 expect(results
.size
).toBe(max
)
208 pool
= new FixedThreadPool(
210 './tests/worker-files/thread/testWorker.js',
211 { workerChoiceStrategy
}
214 for (let i
= 0; i
< max
; i
++) {
215 results
.add(pool
.chooseWorkerNode()[1].worker
.threadId
)
217 expect(results
.size
).toBe(max
)
221 it('Verify ROUND_ROBIN strategy internals are resets after setting it', async () => {
222 const workerChoiceStrategy
= WorkerChoiceStrategies
.ROUND_ROBIN
223 let pool
= new FixedThreadPool(
225 './tests/worker-files/thread/testWorker.js',
226 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
229 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
233 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
235 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
236 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
240 pool
= new DynamicThreadPool(
243 './tests/worker-files/thread/testWorker.js',
244 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
247 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
251 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
253 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
254 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
257 // We need to clean up the resources after our test
261 it('Verify LESS_USED strategy default tasks usage statistics requirements', async () => {
262 const workerChoiceStrategy
= WorkerChoiceStrategies
.LESS_USED
263 let pool
= new FixedThreadPool(
265 './tests/worker-files/thread/testWorker.js',
266 { workerChoiceStrategy
}
269 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
272 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
275 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
278 pool
= new DynamicThreadPool(
281 './tests/worker-files/thread/testWorker.js',
282 { workerChoiceStrategy
}
285 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
288 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
291 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
293 // We need to clean up the resources after our test
297 it('Verify LESS_USED strategy can be run in a fixed pool', async () => {
298 const pool
= new FixedThreadPool(
300 './tests/worker-files/thread/testWorker.js',
301 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_USED
}
303 // TODO: Create a better test to cover `LessUsedWorkerChoiceStrategy#choose`
305 for (let i
= 0; i
< max
* 2; i
++) {
306 promises
.push(pool
.execute())
308 await Promise
.all(promises
)
309 // We need to clean up the resources after our test
313 it('Verify LESS_USED strategy can be run in a dynamic pool', async () => {
314 const pool
= new DynamicThreadPool(
317 './tests/worker-files/thread/testWorker.js',
318 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_USED
}
320 // TODO: Create a better test to cover `LessUsedWorkerChoiceStrategy#choose`
322 for (let i
= 0; i
< max
* 2; i
++) {
323 promises
.push(pool
.execute())
325 await Promise
.all(promises
)
326 // We need to clean up the resources after our test
330 it('Verify LESS_BUSY strategy default tasks usage statistics requirements', async () => {
331 const workerChoiceStrategy
= WorkerChoiceStrategies
.LESS_BUSY
332 let pool
= new FixedThreadPool(
334 './tests/worker-files/thread/testWorker.js',
335 { workerChoiceStrategy
}
338 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
341 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
344 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
347 pool
= new DynamicThreadPool(
350 './tests/worker-files/thread/testWorker.js',
351 { workerChoiceStrategy
}
354 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
357 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
360 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
362 // We need to clean up the resources after our test
366 it('Verify LESS_BUSY strategy can be run in a fixed pool', async () => {
367 const pool
= new FixedThreadPool(
369 './tests/worker-files/thread/testWorker.js',
370 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_BUSY
}
372 // TODO: Create a better test to cover `LessBusyWorkerChoiceStrategy#choose`
374 for (let i
= 0; i
< max
* 2; i
++) {
375 promises
.push(pool
.execute())
377 await Promise
.all(promises
)
378 // We need to clean up the resources after our test
382 it('Verify LESS_BUSY strategy can be run in a dynamic pool', async () => {
383 const pool
= new DynamicThreadPool(
386 './tests/worker-files/thread/testWorker.js',
387 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_BUSY
}
389 // TODO: Create a better test to cover `LessBusyWorkerChoiceStrategy#choose`
391 for (let i
= 0; i
< max
* 2; i
++) {
392 promises
.push(pool
.execute())
394 await Promise
.all(promises
)
395 // We need to clean up the resources after our test
399 it('Verify FAIR_SHARE strategy default tasks usage statistics requirements', async () => {
400 const workerChoiceStrategy
= WorkerChoiceStrategies
.FAIR_SHARE
401 let pool
= new FixedThreadPool(
403 './tests/worker-files/thread/testWorker.js',
404 { workerChoiceStrategy
}
407 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
410 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
413 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
416 pool
= new DynamicThreadPool(
419 './tests/worker-files/thread/testWorker.js',
420 { workerChoiceStrategy
}
423 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
426 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
429 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
431 // We need to clean up the resources after our test
435 it('Verify FAIR_SHARE strategy can be run in a fixed pool', async () => {
436 const pool
= new FixedThreadPool(
438 './tests/worker-files/thread/testWorker.js',
439 { workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
}
441 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
443 for (let i
= 0; i
< max
* 2; i
++) {
444 promises
.push(pool
.execute())
446 await Promise
.all(promises
)
448 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
449 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
450 ).workerLastVirtualTaskTimestamp
.size
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 // if (process.platform !== 'win32') {
472 // pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
473 // pool.workerChoiceStrategyContext.workerChoiceStrategy
474 // ).workerLastVirtualTaskTimestamp.size
475 // ).toBe(pool.workerNodes.length)
477 // We need to clean up the resources after our test
481 it('Verify FAIR_SHARE strategy can be run in a dynamic pool with median run time statistic', async () => {
482 const pool
= new DynamicThreadPool(
485 './tests/worker-files/thread/testWorker.js',
487 workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
,
488 workerChoiceStrategyOptions
: {
493 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
495 const maxMultiplier
= 2
496 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
497 promises
.push(pool
.execute())
499 await Promise
.all(promises
)
500 for (const workerNode
of pool
.workerNodes
) {
501 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
502 expect(workerNode
.tasksUsage
.avgRunTime
).toBe(0)
503 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
504 expect(workerNode
.tasksUsage
.medRunTime
).toBeGreaterThan(0)
506 // if (process.platform !== 'win32') {
508 // pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
509 // pool.workerChoiceStrategyContext.workerChoiceStrategy
510 // ).workerLastVirtualTaskTimestamp.size
511 // ).toBe(pool.workerNodes.length)
513 // We need to clean up the resources after our test
517 it('Verify FAIR_SHARE strategy internals are resets after setting it', async () => {
518 const workerChoiceStrategy
= WorkerChoiceStrategies
.FAIR_SHARE
519 let pool
= new FixedThreadPool(
521 './tests/worker-files/thread/testWorker.js'
524 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
526 ).workerLastVirtualTaskTimestamp
528 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
529 for (const workerNodeKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
530 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
531 .workerLastVirtualTaskTimestamp
.keys()) {
533 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
534 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
535 .workerLastVirtualTaskTimestamp
.get(workerNodeKey
).start
538 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
539 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
540 .workerLastVirtualTaskTimestamp
.get(workerNodeKey
).end
544 pool
= new DynamicThreadPool(
547 './tests/worker-files/thread/testWorker.js'
550 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
552 ).workerLastVirtualTaskTimestamp
554 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
555 for (const workerNodeKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
556 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
557 .workerLastVirtualTaskTimestamp
.keys()) {
559 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
560 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
561 .workerLastVirtualTaskTimestamp
.get(workerNodeKey
).start
564 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
565 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
566 .workerLastVirtualTaskTimestamp
.get(workerNodeKey
).end
569 // We need to clean up the resources after our test
573 it('Verify WEIGHTED_ROUND_ROBIN strategy default tasks usage statistics requirements', async () => {
574 const workerChoiceStrategy
= WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
575 let pool
= new FixedThreadPool(
577 './tests/worker-files/thread/testWorker.js',
578 { workerChoiceStrategy
}
581 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
584 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
587 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
590 pool
= new DynamicThreadPool(
593 './tests/worker-files/thread/testWorker.js',
594 { workerChoiceStrategy
}
597 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
600 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
603 pool
.workerChoiceStrategyContext
.getRequiredStatistics().medRunTime
605 // We need to clean up the resources after our test
609 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a fixed pool', async () => {
610 const pool
= new FixedThreadPool(
612 './tests/worker-files/thread/testWorker.js',
613 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
615 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
617 for (let i
= 0; i
< max
* 2; i
++) {
618 promises
.push(pool
.execute())
620 await Promise
.all(promises
)
622 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
623 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
624 ).workersTaskRunTime
.size
625 ).toBe(pool
.workerNodes
.length
)
626 // We need to clean up the resources after our test
630 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a dynamic pool', async () => {
631 const pool
= new DynamicThreadPool(
634 './tests/worker-files/thread/testWorker.js',
635 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
637 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
639 const maxMultiplier
=
640 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
641 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
642 ).defaultWorkerWeight
* 50
643 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
644 promises
.push(pool
.execute())
646 await Promise
.all(promises
)
647 if (process
.platform
!== 'win32') {
649 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
650 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
651 ).workersTaskRunTime
.size
652 ).toBe(pool
.workerNodes
.length
)
654 // We need to clean up the resources after our test
658 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a dynamic pool with median run time statistic', async () => {
659 const pool
= new DynamicThreadPool(
662 './tests/worker-files/thread/testWorker.js',
664 workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
,
665 workerChoiceStrategyOptions
: {
670 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
672 const maxMultiplier
= 2
673 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
674 promises
.push(pool
.execute())
676 await Promise
.all(promises
)
677 for (const workerNode
of pool
.workerNodes
) {
678 expect(workerNode
.tasksUsage
.avgRunTime
).toBeDefined()
679 expect(workerNode
.tasksUsage
.avgRunTime
).toBe(0)
680 expect(workerNode
.tasksUsage
.medRunTime
).toBeDefined()
681 expect(workerNode
.tasksUsage
.medRunTime
).toBeGreaterThan(0)
683 // if (process.platform !== 'win32') {
685 // pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
686 // pool.workerChoiceStrategyContext.workerChoiceStrategy
687 // ).workersTaskRunTime.size
688 // ).toBe(pool.workerNodes.length)
690 // We need to clean up the resources after our test
694 it('Verify WEIGHTED_ROUND_ROBIN strategy internals are resets after setting it', async () => {
695 const workerChoiceStrategy
= WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
696 let pool
= new FixedThreadPool(
698 './tests/worker-files/thread/testWorker.js'
701 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
703 ).currentWorkerNodeId
706 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
708 ).defaultWorkerWeight
711 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
715 pool
.setWorkerChoiceStrategy(workerChoiceStrategy
)
717 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
718 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
719 ).currentWorkerNodeId
722 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
723 pool
.workerChoiceStrategyContext
.workerChoiceStrategy
724 ).defaultWorkerWeight
726 for (const workerNodeKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
727 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
728 .workersTaskRunTime
.keys()) {
730 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
731 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
732 .workersTaskRunTime
.get(workerNodeKey
).runTime
736 pool
= new DynamicThreadPool(
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(
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
767 for (const workerNodeKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
768 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
769 .workersTaskRunTime
.keys()) {
771 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
772 .get(pool
.workerChoiceStrategyContext
.workerChoiceStrategy
)
773 .workersTaskRunTime
.get(workerNodeKey
).runTime
776 // We need to clean up the resources after our test
780 it('Verify unknown strategy throw error', () => {
783 new DynamicThreadPool(
786 './tests/worker-files/thread/testWorker.js',
787 { workerChoiceStrategy
: 'UNKNOWN_STRATEGY' }
789 ).toThrowError("Invalid worker choice strategy 'UNKNOWN_STRATEGY'")