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 ROUND_ROBIN strategy is taken at pool creation', async () => {
37 const pool
= new FixedThreadPool(
39 './tests/worker-files/thread/testWorker.js',
40 { workerChoiceStrategy
: WorkerChoiceStrategies
.ROUND_ROBIN
}
42 expect(pool
.opts
.workerChoiceStrategy
).toBe(
43 WorkerChoiceStrategies
.ROUND_ROBIN
46 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
47 WorkerChoiceStrategies
.ROUND_ROBIN
50 // We need to clean up the resources after our test
54 it('Verify ROUND_ROBIN strategy can be set after pool creation', async () => {
55 const pool
= new DynamicThreadPool(
58 './tests/worker-files/thread/testWorker.js'
60 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.ROUND_ROBIN
)
61 expect(pool
.opts
.workerChoiceStrategy
).toBe(
62 WorkerChoiceStrategies
.ROUND_ROBIN
64 // We need to clean up the resources after our test
68 it('Verify ROUND_ROBIN strategy default tasks usage statistics requirements', async () => {
69 let pool
= new FixedThreadPool(
71 './tests/worker-files/thread/testWorker.js'
73 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.ROUND_ROBIN
)
75 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
78 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
81 pool
= new DynamicThreadPool(
84 './tests/worker-files/thread/testWorker.js'
86 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.ROUND_ROBIN
)
88 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
91 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
93 // We need to clean up the resources after our test
97 it('Verify ROUND_ROBIN strategy can be run in a fixed pool', async () => {
98 const pool
= new FixedThreadPool(
100 './tests/worker-files/thread/testWorker.js',
101 { workerChoiceStrategy
: WorkerChoiceStrategies
.ROUND_ROBIN
}
103 expect(pool
.opts
.workerChoiceStrategy
).toBe(
104 WorkerChoiceStrategies
.ROUND_ROBIN
106 // TODO: Create a better test to cover `RoundRobinWorkerChoiceStrategy#choose`
108 for (let i
= 0; i
< max
* 2; i
++) {
109 promises
.push(pool
.execute())
111 await Promise
.all(promises
)
112 // We need to clean up the resources after our test
116 it('Verify ROUND_ROBIN strategy can be run in a dynamic pool', async () => {
117 const pool
= new DynamicThreadPool(
120 './tests/worker-files/thread/testWorker.js',
121 { workerChoiceStrategy
: WorkerChoiceStrategies
.ROUND_ROBIN
}
123 expect(pool
.opts
.workerChoiceStrategy
).toBe(
124 WorkerChoiceStrategies
.ROUND_ROBIN
126 // TODO: Create a better test to cover `RoundRobinWorkerChoiceStrategy#choose`
128 for (let i
= 0; i
< max
* 2; i
++) {
129 promises
.push(pool
.execute())
131 await Promise
.all(promises
)
132 // We need to clean up the resources after our test
136 it('Verify ROUND_ROBIN strategy runtime behavior', async () => {
137 let pool
= new FixedClusterPool(
139 './tests/worker-files/cluster/testWorker.js'
141 let results
= new Set()
142 for (let i
= 0; i
< max
; i
++) {
143 results
.add(pool
.chooseWorker()[1].id
)
145 expect(results
.size
).toBe(max
)
147 pool
= new FixedThreadPool(max
, './tests/worker-files/thread/testWorker.js')
149 for (let i
= 0; i
< max
; i
++) {
150 results
.add(pool
.chooseWorker()[1].threadId
)
152 expect(results
.size
).toBe(max
)
156 it('Verify ROUND_ROBIN strategy internals are resets after setting it', async () => {
157 let pool
= new FixedThreadPool(
159 './tests/worker-files/thread/testWorker.js',
160 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
163 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
164 WorkerChoiceStrategies
.ROUND_ROBIN
167 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.ROUND_ROBIN
)
169 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
170 WorkerChoiceStrategies
.ROUND_ROBIN
174 pool
= new DynamicThreadPool(
177 './tests/worker-files/thread/testWorker.js',
178 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
181 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
182 WorkerChoiceStrategies
.ROUND_ROBIN
185 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.ROUND_ROBIN
)
187 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
188 WorkerChoiceStrategies
.ROUND_ROBIN
191 // We need to clean up the resources after our test
195 it('Verify LESS_USED strategy is taken at pool creation', async () => {
196 const pool
= new FixedThreadPool(
198 './tests/worker-files/thread/testWorker.js',
199 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_USED
}
201 expect(pool
.opts
.workerChoiceStrategy
).toBe(
202 WorkerChoiceStrategies
.LESS_USED
204 // We need to clean up the resources after our test
208 it('Verify LESS_USED strategy can be set after pool creation', async () => {
209 const pool
= new FixedThreadPool(
211 './tests/worker-files/thread/testWorker.js'
213 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.LESS_USED
)
214 expect(pool
.opts
.workerChoiceStrategy
).toBe(
215 WorkerChoiceStrategies
.LESS_USED
217 // We need to clean up the resources after our test
221 it('Verify LESS_USED strategy default tasks usage statistics requirements', async () => {
222 let pool
= new FixedThreadPool(
224 './tests/worker-files/thread/testWorker.js'
226 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.LESS_USED
)
228 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
231 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
234 pool
= new DynamicThreadPool(
237 './tests/worker-files/thread/testWorker.js'
239 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.LESS_USED
)
241 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
244 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
246 // We need to clean up the resources after our test
250 it('Verify LESS_USED strategy can be run in a fixed pool', async () => {
251 const pool
= new FixedThreadPool(
253 './tests/worker-files/thread/testWorker.js',
254 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_USED
}
256 // TODO: Create a better test to cover `LessUsedWorkerChoiceStrategy#choose`
258 for (let i
= 0; i
< max
* 2; i
++) {
259 promises
.push(pool
.execute())
261 await Promise
.all(promises
)
262 // We need to clean up the resources after our test
266 it('Verify LESS_USED strategy can be run in a dynamic pool', async () => {
267 const pool
= new DynamicThreadPool(
270 './tests/worker-files/thread/testWorker.js',
271 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_USED
}
273 // TODO: Create a better test to cover `LessUsedWorkerChoiceStrategy#choose`
275 for (let i
= 0; i
< max
* 2; i
++) {
276 promises
.push(pool
.execute())
278 await Promise
.all(promises
)
279 // We need to clean up the resources after our test
283 it('Verify LESS_BUSY strategy is taken at pool creation', async () => {
284 const pool
= new FixedThreadPool(
286 './tests/worker-files/thread/testWorker.js',
287 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_BUSY
}
289 expect(pool
.opts
.workerChoiceStrategy
).toBe(
290 WorkerChoiceStrategies
.LESS_BUSY
292 // We need to clean up the resources after our test
296 it('Verify LESS_BUSY strategy can be set after pool creation', async () => {
297 const pool
= new FixedThreadPool(
299 './tests/worker-files/thread/testWorker.js'
301 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.LESS_BUSY
)
302 expect(pool
.opts
.workerChoiceStrategy
).toBe(
303 WorkerChoiceStrategies
.LESS_BUSY
305 // We need to clean up the resources after our test
309 it('Verify LESS_BUSY strategy default tasks usage statistics requirements', async () => {
310 let pool
= new FixedThreadPool(
312 './tests/worker-files/thread/testWorker.js'
314 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.LESS_BUSY
)
316 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
319 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
322 pool
= new DynamicThreadPool(
325 './tests/worker-files/thread/testWorker.js'
327 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.LESS_BUSY
)
329 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
332 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
334 // We need to clean up the resources after our test
338 it('Verify LESS_BUSY strategy can be run in a fixed pool', async () => {
339 const pool
= new FixedThreadPool(
341 './tests/worker-files/thread/testWorker.js',
342 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_BUSY
}
344 // TODO: Create a better test to cover `LessBusyWorkerChoiceStrategy#choose`
346 for (let i
= 0; i
< max
* 2; i
++) {
347 promises
.push(pool
.execute())
349 await Promise
.all(promises
)
350 // We need to clean up the resources after our test
354 it('Verify LESS_BUSY strategy can be run in a dynamic pool', async () => {
355 const pool
= new DynamicThreadPool(
358 './tests/worker-files/thread/testWorker.js',
359 { workerChoiceStrategy
: WorkerChoiceStrategies
.LESS_BUSY
}
361 // TODO: Create a better test to cover `LessBusyWorkerChoiceStrategy#choose`
363 for (let i
= 0; i
< max
* 2; i
++) {
364 promises
.push(pool
.execute())
366 await Promise
.all(promises
)
367 // We need to clean up the resources after our test
371 it('Verify FAIR_SHARE strategy is taken at pool creation', async () => {
372 const pool
= new FixedThreadPool(
374 './tests/worker-files/thread/testWorker.js',
375 { workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
}
377 expect(pool
.opts
.workerChoiceStrategy
).toBe(
378 WorkerChoiceStrategies
.FAIR_SHARE
380 for (const workerKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
381 .get(WorkerChoiceStrategies
.FAIR_SHARE
)
382 .workerLastVirtualTaskTimestamp
.keys()) {
384 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
385 .get(WorkerChoiceStrategies
.FAIR_SHARE
)
386 .workerLastVirtualTaskTimestamp
.get(workerKey
).start
389 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
390 .get(WorkerChoiceStrategies
.FAIR_SHARE
)
391 .workerLastVirtualTaskTimestamp
.get(workerKey
).end
394 // We need to clean up the resources after our test
398 it('Verify FAIR_SHARE strategy can be set after pool creation', async () => {
399 const pool
= new FixedThreadPool(
401 './tests/worker-files/thread/testWorker.js'
403 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.FAIR_SHARE
)
404 expect(pool
.opts
.workerChoiceStrategy
).toBe(
405 WorkerChoiceStrategies
.FAIR_SHARE
407 // We need to clean up the resources after our test
411 it('Verify FAIR_SHARE strategy default tasks usage statistics requirements', async () => {
412 let pool
= new FixedThreadPool(
414 './tests/worker-files/thread/testWorker.js'
416 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.FAIR_SHARE
)
418 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
421 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
424 pool
= new DynamicThreadPool(
427 './tests/worker-files/thread/testWorker.js'
429 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.FAIR_SHARE
)
431 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
434 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
436 // We need to clean up the resources after our test
440 it('Verify FAIR_SHARE strategy can be run in a fixed pool', async () => {
441 const pool
= new FixedThreadPool(
443 './tests/worker-files/thread/testWorker.js',
444 { workerChoiceStrategy
: WorkerChoiceStrategies
.FAIR_SHARE
}
446 // TODO: Create a better test to cover `FairShareChoiceStrategy#choose`
448 for (let i
= 0; i
< max
* 2; i
++) {
449 promises
.push(pool
.execute())
451 await Promise
.all(promises
)
453 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
454 WorkerChoiceStrategies
.FAIR_SHARE
455 ).workerLastVirtualTaskTimestamp
.size
456 ).toBe(pool
.workers
.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`
470 const maxMultiplier
= 2
471 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
472 promises
.push(pool
.execute())
474 await Promise
.all(promises
)
475 // if (process.platform !== 'win32') {
477 // pool.workerChoiceStrategyContext.workerChoiceStrategies.get(
478 // WorkerChoiceStrategies.FAIR_SHARE
479 // ).workerLastVirtualTaskTimestamp.size
480 // ).toBe(pool.workers.length)
482 // We need to clean up the resources after our test
486 it('Verify FAIR_SHARE strategy internals are resets after setting it', async () => {
487 let pool
= new FixedThreadPool(
489 './tests/worker-files/thread/testWorker.js'
492 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
493 WorkerChoiceStrategies
.FAIR_SHARE
494 ).workerLastVirtualTaskTimestamp
496 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.FAIR_SHARE
)
497 for (const workerKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
498 .get(WorkerChoiceStrategies
.FAIR_SHARE
)
499 .workerLastVirtualTaskTimestamp
.keys()) {
501 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
502 .get(WorkerChoiceStrategies
.FAIR_SHARE
)
503 .workerLastVirtualTaskTimestamp
.get(workerKey
).start
506 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
507 .get(WorkerChoiceStrategies
.FAIR_SHARE
)
508 .workerLastVirtualTaskTimestamp
.get(workerKey
).end
512 pool
= new DynamicThreadPool(
515 './tests/worker-files/thread/testWorker.js'
518 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
519 WorkerChoiceStrategies
.FAIR_SHARE
520 ).workerLastVirtualTaskTimestamp
522 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.FAIR_SHARE
)
523 for (const workerKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
524 .get(WorkerChoiceStrategies
.FAIR_SHARE
)
525 .workerLastVirtualTaskTimestamp
.keys()) {
527 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
528 .get(WorkerChoiceStrategies
.FAIR_SHARE
)
529 .workerLastVirtualTaskTimestamp
.get(workerKey
).start
532 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
533 .get(WorkerChoiceStrategies
.FAIR_SHARE
)
534 .workerLastVirtualTaskTimestamp
.get(workerKey
).end
537 // We need to clean up the resources after our test
541 it('Verify WEIGHTED_ROUND_ROBIN strategy is taken at pool creation', async () => {
542 const pool
= new FixedThreadPool(
544 './tests/worker-files/thread/testWorker.js',
545 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
547 expect(pool
.opts
.workerChoiceStrategy
).toBe(
548 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
551 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
552 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
556 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
557 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
558 ).defaultWorkerWeight
560 for (const workerKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
561 .get(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
562 .workersTaskRunTime
.keys()) {
564 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
565 .get(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
566 .workersTaskRunTime
.get(workerKey
).weight
569 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
570 .get(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
571 .workersTaskRunTime
.get(workerKey
).runTime
574 // We need to clean up the resources after our test
578 it('Verify WEIGHTED_ROUND_ROBIN strategy can be set after pool creation', async () => {
579 const pool
= new FixedThreadPool(
581 './tests/worker-files/thread/testWorker.js'
583 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
584 expect(pool
.opts
.workerChoiceStrategy
).toBe(
585 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
587 // We need to clean up the resources after our test
591 it('Verify WEIGHTED_ROUND_ROBIN strategy default tasks usage statistics requirements', async () => {
592 let pool
= new FixedThreadPool(
594 './tests/worker-files/thread/testWorker.js'
596 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
598 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
601 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
604 pool
= new DynamicThreadPool(
607 './tests/worker-files/thread/testWorker.js'
609 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
611 pool
.workerChoiceStrategyContext
.getRequiredStatistics().runTime
614 pool
.workerChoiceStrategyContext
.getRequiredStatistics().avgRunTime
616 // We need to clean up the resources after our test
620 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a fixed pool', async () => {
621 const pool
= new FixedThreadPool(
623 './tests/worker-files/thread/testWorker.js',
624 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
626 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
628 for (let i
= 0; i
< max
* 2; i
++) {
629 promises
.push(pool
.execute())
631 await Promise
.all(promises
)
633 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
634 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
635 ).workersTaskRunTime
.size
636 ).toBe(pool
.workers
.length
)
637 // We need to clean up the resources after our test
641 it('Verify WEIGHTED_ROUND_ROBIN strategy can be run in a dynamic pool', async () => {
642 const pool
= new DynamicThreadPool(
645 './tests/worker-files/thread/testWorker.js',
646 { workerChoiceStrategy
: WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
}
648 // TODO: Create a better test to cover `WeightedRoundRobinWorkerChoiceStrategy#choose`
650 const maxMultiplier
=
651 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
652 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
653 ).defaultWorkerWeight
* 2
654 for (let i
= 0; i
< max
* maxMultiplier
; i
++) {
655 promises
.push(pool
.execute())
657 await Promise
.all(promises
)
658 if (process
.platform
!== 'win32') {
660 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
661 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
662 ).workersTaskRunTime
.size
663 ).toBe(pool
.workers
.length
)
665 // We need to clean up the resources after our test
669 it('Verify WEIGHTED_ROUND_ROBIN strategy internals are resets after setting it', async () => {
670 let pool
= new FixedThreadPool(
672 './tests/worker-files/thread/testWorker.js'
675 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
676 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
680 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
681 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
682 ).defaultWorkerWeight
685 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
686 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
689 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
691 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
692 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
696 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
697 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
698 ).defaultWorkerWeight
700 for (const workerKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
701 .get(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
702 .workersTaskRunTime
.keys()) {
704 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
705 .get(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
706 .workersTaskRunTime
.get(workerKey
).runTime
710 pool
= new DynamicThreadPool(
713 './tests/worker-files/thread/testWorker.js'
716 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
717 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
721 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
722 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
723 ).defaultWorkerWeight
726 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
727 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
730 pool
.setWorkerChoiceStrategy(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
732 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
733 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
737 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
.get(
738 WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
739 ).defaultWorkerWeight
741 for (const workerKey
of pool
.workerChoiceStrategyContext
.workerChoiceStrategies
742 .get(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
743 .workersTaskRunTime
.keys()) {
745 pool
.workerChoiceStrategyContext
.workerChoiceStrategies
746 .get(WorkerChoiceStrategies
.WEIGHTED_ROUND_ROBIN
)
747 .workersTaskRunTime
.get(workerKey
).runTime
750 // We need to clean up the resources after our test
754 it('Verify unknown strategies throw error', () => {
757 new DynamicThreadPool(
760 './tests/worker-files/thread/testWorker.js',
761 { workerChoiceStrategy
: 'UNKNOWN_STRATEGY' }
764 new Error("Invalid worker choice strategy 'UNKNOWN_STRATEGY'")