fix: ensure worker choice is retried at least the pool max size
[poolifier.git] / tests / pools / selection-strategies / worker-choice-strategy-context.test.mjs
CommitLineData
a074ffee
JB
1import { expect } from 'expect'
2import { createStubInstance, restore, stub } from 'sinon'
3import {
40ad1d27 4 DynamicThreadPool,
a074ffee 5 FixedThreadPool,
40ad1d27 6 WorkerChoiceStrategies
a074ffee
JB
7} from '../../../lib/index.js'
8import { WorkerChoiceStrategyContext } from '../../../lib/pools/selection-strategies/worker-choice-strategy-context.js'
9import { RoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/round-robin-worker-choice-strategy.js'
10import { LeastUsedWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-used-worker-choice-strategy.js'
11import { LeastBusyWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-busy-worker-choice-strategy.js'
12import { LeastEluWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/least-elu-worker-choice-strategy.js'
13import { FairShareWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/fair-share-worker-choice-strategy.js'
14import { WeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/weighted-round-robin-worker-choice-strategy.js'
15import { InterleavedWeightedRoundRobinWorkerChoiceStrategy } from '../../../lib/pools/selection-strategies/interleaved-weighted-round-robin-worker-choice-strategy.js'
40ad1d27
JB
16
17describe('Worker choice strategy context test suite', () => {
c15273f2
JB
18 const min = 1
19 const max = 3
40ad1d27 20 let fixedPool, dynamicPool
c15273f2
JB
21
22 before(() => {
23 fixedPool = new FixedThreadPool(
24 max,
b2fd3f4a 25 './tests/worker-files/thread/testWorker.mjs'
c15273f2
JB
26 )
27 dynamicPool = new DynamicThreadPool(
28 min,
29 max,
b2fd3f4a 30 './tests/worker-files/thread/testWorker.mjs'
c15273f2 31 )
40ad1d27
JB
32 })
33
34 afterEach(() => {
a074ffee 35 restore()
40ad1d27
JB
36 })
37
fd7ebd49
JB
38 after(async () => {
39 await fixedPool.destroy()
40 await dynamicPool.destroy()
c15273f2
JB
41 })
42
2285a040
JB
43 it('Verify that constructor() initializes the context with all the available worker choice strategies', () => {
44 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
45 fixedPool
46 )
47 expect(workerChoiceStrategyContext.workerChoiceStrategies.size).toBe(
48 Object.keys(WorkerChoiceStrategies).length
49 )
50 })
51
fb5a7307 52 it('Verify that execute() return the worker node key chosen by the strategy with fixed pool', () => {
40ad1d27
JB
53 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
54 fixedPool
55 )
33d2304b 56 const workerChoiceStrategyStub = createStubInstance(
40ad1d27
JB
57 RoundRobinWorkerChoiceStrategy,
58 {
fb5a7307 59 hasPoolWorkerNodesReady: stub().returns(true),
a074ffee 60 choose: stub().returns(0)
40ad1d27
JB
61 }
62 )
d710242d 63 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
95c83464
JB
64 WorkerChoiceStrategies.ROUND_ROBIN
65 )
66 workerChoiceStrategyContext.workerChoiceStrategies.set(
d710242d 67 workerChoiceStrategyContext.workerChoiceStrategy,
33d2304b 68 workerChoiceStrategyStub
95c83464 69 )
c923ce56 70 const chosenWorkerKey = workerChoiceStrategyContext.execute()
40ad1d27 71 expect(
95c83464 72 workerChoiceStrategyContext.workerChoiceStrategies.get(
d710242d 73 workerChoiceStrategyContext.workerChoiceStrategy
95c83464 74 ).choose.calledOnce
40ad1d27 75 ).toBe(true)
c923ce56 76 expect(chosenWorkerKey).toBe(0)
40ad1d27
JB
77 })
78
4ba8492f 79 it('Verify that execute() throws error if null or undefined is returned after retries', () => {
527e715f
JB
80 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
81 fixedPool
82 )
6ff68506
JB
83 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
84 WorkerChoiceStrategies.ROUND_ROBIN
85 )
33d2304b 86 const workerChoiceStrategyUndefinedStub = createStubInstance(
527e715f
JB
87 RoundRobinWorkerChoiceStrategy,
88 {
fb5a7307 89 hasPoolWorkerNodesReady: stub().returns(true),
a074ffee 90 choose: stub().returns(undefined)
527e715f
JB
91 }
92 )
527e715f
JB
93 workerChoiceStrategyContext.workerChoiceStrategies.set(
94 workerChoiceStrategyContext.workerChoiceStrategy,
33d2304b 95 workerChoiceStrategyUndefinedStub
fa418e12 96 )
948faff7 97 expect(() => workerChoiceStrategyContext.execute()).toThrow(
26ce26ca
JB
98 new Error(
99 `Worker node key chosen is null or undefined after ${fixedPool.info.maxSize} retries`
100 )
fa418e12 101 )
6ff68506
JB
102 const workerChoiceStrategyNullStub = createStubInstance(
103 RoundRobinWorkerChoiceStrategy,
104 {
105 hasPoolWorkerNodesReady: stub().returns(true),
106 choose: stub().returns(null)
107 }
108 )
fa418e12
JB
109 workerChoiceStrategyContext.workerChoiceStrategies.set(
110 workerChoiceStrategyContext.workerChoiceStrategy,
33d2304b 111 workerChoiceStrategyNullStub
527e715f 112 )
948faff7 113 expect(() => workerChoiceStrategyContext.execute()).toThrow(
26ce26ca
JB
114 new Error(
115 `Worker node key chosen is null or undefined after ${fixedPool.info.maxSize} retries`
116 )
527e715f
JB
117 )
118 })
119
fb5a7307
JB
120 it('Verify that execute() retry until a worker node is ready and chosen', () => {
121 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
122 fixedPool
123 )
124 const workerChoiceStrategyStub = createStubInstance(
125 RoundRobinWorkerChoiceStrategy,
126 {
127 hasPoolWorkerNodesReady: stub()
128 .onCall(0)
129 .returns(false)
130 .onCall(1)
131 .returns(false)
132 .onCall(2)
133 .returns(false)
134 .onCall(3)
135 .returns(false)
136 .onCall(4)
137 .returns(false)
fb5a7307
JB
138 .returns(true),
139 choose: stub().returns(1)
140 }
141 )
142 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
143 WorkerChoiceStrategies.ROUND_ROBIN
144 )
145 workerChoiceStrategyContext.workerChoiceStrategies.set(
146 workerChoiceStrategyContext.workerChoiceStrategy,
147 workerChoiceStrategyStub
148 )
149 const chosenWorkerKey = workerChoiceStrategyContext.execute()
150 expect(
151 workerChoiceStrategyContext.workerChoiceStrategies.get(
152 workerChoiceStrategyContext.workerChoiceStrategy
153 ).hasPoolWorkerNodesReady.callCount
722d55a0 154 ).toBe(6)
fb5a7307
JB
155 expect(
156 workerChoiceStrategyContext.workerChoiceStrategies.get(
157 workerChoiceStrategyContext.workerChoiceStrategy
158 ).choose.callCount
159 ).toBe(1)
160 expect(chosenWorkerKey).toBe(1)
161 })
162
722d55a0 163 it('Verify that execute() throws error if worker choice strategy recursion reach the maximum depth', () => {
fb5a7307
JB
164 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
165 fixedPool
166 )
167 const workerChoiceStrategyStub = createStubInstance(
168 RoundRobinWorkerChoiceStrategy,
169 {
170 hasPoolWorkerNodesReady: stub().returns(false),
171 choose: stub().returns(0)
172 }
173 )
174 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
175 WorkerChoiceStrategies.ROUND_ROBIN
176 )
177 workerChoiceStrategyContext.workerChoiceStrategies.set(
178 workerChoiceStrategyContext.workerChoiceStrategy,
179 workerChoiceStrategyStub
180 )
181 expect(() => workerChoiceStrategyContext.execute()).toThrow(
722d55a0 182 new RangeError('Maximum call stack size exceeded')
fb5a7307
JB
183 )
184 })
185
186 it('Verify that execute() return the worker node key chosen by the strategy with dynamic pool', () => {
40ad1d27
JB
187 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
188 dynamicPool
189 )
33d2304b 190 const workerChoiceStrategyStub = createStubInstance(
40ad1d27
JB
191 RoundRobinWorkerChoiceStrategy,
192 {
fb5a7307 193 hasPoolWorkerNodesReady: stub().returns(true),
a074ffee 194 choose: stub().returns(0)
40ad1d27
JB
195 }
196 )
d710242d 197 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
95c83464
JB
198 WorkerChoiceStrategies.ROUND_ROBIN
199 )
200 workerChoiceStrategyContext.workerChoiceStrategies.set(
d710242d 201 workerChoiceStrategyContext.workerChoiceStrategy,
33d2304b 202 workerChoiceStrategyStub
95c83464 203 )
c923ce56 204 const chosenWorkerKey = workerChoiceStrategyContext.execute()
40ad1d27 205 expect(
95c83464 206 workerChoiceStrategyContext.workerChoiceStrategies.get(
d710242d 207 workerChoiceStrategyContext.workerChoiceStrategy
95c83464 208 ).choose.calledOnce
40ad1d27 209 ).toBe(true)
c923ce56 210 expect(chosenWorkerKey).toBe(0)
40ad1d27
JB
211 })
212
213 it('Verify that setWorkerChoiceStrategy() works with ROUND_ROBIN and fixed pool', () => {
594bfb84 214 const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN
40ad1d27
JB
215 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
216 fixedPool
217 )
95c83464
JB
218 expect(
219 workerChoiceStrategyContext.workerChoiceStrategies.get(
594bfb84 220 workerChoiceStrategy
95c83464
JB
221 )
222 ).toBeInstanceOf(RoundRobinWorkerChoiceStrategy)
d710242d 223 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
594bfb84 224 workerChoiceStrategy
40ad1d27 225 )
594bfb84 226 workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy)
95c83464
JB
227 expect(
228 workerChoiceStrategyContext.workerChoiceStrategies.get(
594bfb84 229 workerChoiceStrategy
95c83464
JB
230 )
231 ).toBeInstanceOf(RoundRobinWorkerChoiceStrategy)
d710242d 232 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
594bfb84 233 workerChoiceStrategy
b2b1d84e 234 )
40ad1d27
JB
235 })
236
23ff945a 237 it('Verify that setWorkerChoiceStrategy() works with ROUND_ROBIN and dynamic pool', () => {
594bfb84 238 const workerChoiceStrategy = WorkerChoiceStrategies.ROUND_ROBIN
40ad1d27
JB
239 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
240 dynamicPool
241 )
95c83464
JB
242 expect(
243 workerChoiceStrategyContext.workerChoiceStrategies.get(
594bfb84 244 workerChoiceStrategy
95c83464
JB
245 )
246 ).toBeInstanceOf(RoundRobinWorkerChoiceStrategy)
d710242d 247 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
594bfb84 248 workerChoiceStrategy
40ad1d27 249 )
594bfb84 250 workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy)
95c83464
JB
251 expect(
252 workerChoiceStrategyContext.workerChoiceStrategies.get(
594bfb84 253 workerChoiceStrategy
95c83464
JB
254 )
255 ).toBeInstanceOf(RoundRobinWorkerChoiceStrategy)
d710242d 256 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
594bfb84 257 workerChoiceStrategy
b2b1d84e 258 )
40ad1d27
JB
259 })
260
e4543b14
JB
261 it('Verify that setWorkerChoiceStrategy() works with LEAST_USED and fixed pool', () => {
262 const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_USED
40ad1d27
JB
263 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
264 fixedPool
265 )
594bfb84 266 workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy)
95c83464
JB
267 expect(
268 workerChoiceStrategyContext.workerChoiceStrategies.get(
594bfb84 269 workerChoiceStrategy
95c83464 270 )
e4543b14 271 ).toBeInstanceOf(LeastUsedWorkerChoiceStrategy)
d710242d 272 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
594bfb84 273 workerChoiceStrategy
b2b1d84e 274 )
40ad1d27
JB
275 })
276
e4543b14
JB
277 it('Verify that setWorkerChoiceStrategy() works with LEAST_USED and dynamic pool', () => {
278 const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_USED
40ad1d27
JB
279 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
280 dynamicPool
281 )
594bfb84 282 workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy)
95c83464
JB
283 expect(
284 workerChoiceStrategyContext.workerChoiceStrategies.get(
594bfb84 285 workerChoiceStrategy
95c83464 286 )
e4543b14 287 ).toBeInstanceOf(LeastUsedWorkerChoiceStrategy)
d710242d 288 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
594bfb84 289 workerChoiceStrategy
b2b1d84e 290 )
168c526f
JB
291 })
292
e4543b14
JB
293 it('Verify that setWorkerChoiceStrategy() works with LEAST_BUSY and fixed pool', () => {
294 const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_BUSY
168c526f
JB
295 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
296 fixedPool
297 )
594bfb84 298 workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy)
95c83464
JB
299 expect(
300 workerChoiceStrategyContext.workerChoiceStrategies.get(
594bfb84 301 workerChoiceStrategy
95c83464 302 )
e4543b14 303 ).toBeInstanceOf(LeastBusyWorkerChoiceStrategy)
d710242d 304 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
594bfb84 305 workerChoiceStrategy
b2b1d84e 306 )
168c526f
JB
307 })
308
e4543b14
JB
309 it('Verify that setWorkerChoiceStrategy() works with LEAST_BUSY and dynamic pool', () => {
310 const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_BUSY
168c526f
JB
311 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
312 dynamicPool
313 )
594bfb84 314 workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy)
95c83464
JB
315 expect(
316 workerChoiceStrategyContext.workerChoiceStrategies.get(
594bfb84 317 workerChoiceStrategy
95c83464 318 )
e4543b14 319 ).toBeInstanceOf(LeastBusyWorkerChoiceStrategy)
d710242d 320 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
594bfb84 321 workerChoiceStrategy
b2b1d84e 322 )
40ad1d27 323 })
23ff945a 324
a1c82d5d
JB
325 it('Verify that setWorkerChoiceStrategy() works with LEAST_ELU and fixed pool', () => {
326 const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_ELU
327 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
328 fixedPool
329 )
330 workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy)
331 expect(
332 workerChoiceStrategyContext.workerChoiceStrategies.get(
333 workerChoiceStrategy
334 )
335 ).toBeInstanceOf(LeastEluWorkerChoiceStrategy)
336 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
337 workerChoiceStrategy
338 )
339 })
340
341 it('Verify that setWorkerChoiceStrategy() works with LEAST_ELU and dynamic pool', () => {
342 const workerChoiceStrategy = WorkerChoiceStrategies.LEAST_ELU
343 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
344 dynamicPool
345 )
346 workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy)
347 expect(
348 workerChoiceStrategyContext.workerChoiceStrategies.get(
349 workerChoiceStrategy
350 )
351 ).toBeInstanceOf(LeastEluWorkerChoiceStrategy)
352 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
353 workerChoiceStrategy
354 )
355 })
356
23ff945a 357 it('Verify that setWorkerChoiceStrategy() works with FAIR_SHARE and fixed pool', () => {
594bfb84 358 const workerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE
23ff945a
JB
359 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
360 fixedPool
361 )
594bfb84 362 workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy)
95c83464
JB
363 expect(
364 workerChoiceStrategyContext.workerChoiceStrategies.get(
594bfb84 365 workerChoiceStrategy
95c83464
JB
366 )
367 ).toBeInstanceOf(FairShareWorkerChoiceStrategy)
d710242d 368 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
594bfb84 369 workerChoiceStrategy
b2b1d84e 370 )
23ff945a
JB
371 })
372
373 it('Verify that setWorkerChoiceStrategy() works with FAIR_SHARE and dynamic pool', () => {
594bfb84 374 const workerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE
23ff945a
JB
375 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
376 dynamicPool
377 )
594bfb84 378 workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy)
95c83464
JB
379 expect(
380 workerChoiceStrategyContext.workerChoiceStrategies.get(
594bfb84 381 workerChoiceStrategy
95c83464
JB
382 )
383 ).toBeInstanceOf(FairShareWorkerChoiceStrategy)
d710242d 384 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
594bfb84 385 workerChoiceStrategy
b2b1d84e 386 )
23ff945a
JB
387 })
388
c15273f2 389 it('Verify that setWorkerChoiceStrategy() works with WEIGHTED_ROUND_ROBIN and fixed pool', () => {
594bfb84 390 const workerChoiceStrategy = WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
c15273f2
JB
391 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
392 fixedPool
393 )
594bfb84 394 workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy)
95c83464
JB
395 expect(
396 workerChoiceStrategyContext.workerChoiceStrategies.get(
594bfb84 397 workerChoiceStrategy
95c83464
JB
398 )
399 ).toBeInstanceOf(WeightedRoundRobinWorkerChoiceStrategy)
d710242d 400 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
594bfb84 401 workerChoiceStrategy
b2b1d84e 402 )
c15273f2 403 })
23ff945a 404
c15273f2 405 it('Verify that setWorkerChoiceStrategy() works with WEIGHTED_ROUND_ROBIN and dynamic pool', () => {
594bfb84 406 const workerChoiceStrategy = WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
c15273f2
JB
407 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
408 dynamicPool
409 )
594bfb84 410 workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy)
95c83464
JB
411 expect(
412 workerChoiceStrategyContext.workerChoiceStrategies.get(
594bfb84 413 workerChoiceStrategy
95c83464
JB
414 )
415 ).toBeInstanceOf(WeightedRoundRobinWorkerChoiceStrategy)
d710242d 416 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
594bfb84 417 workerChoiceStrategy
b2b1d84e 418 )
c15273f2 419 })
2fc5cae3 420
8beab0d3
JB
421 it('Verify that setWorkerChoiceStrategy() works with INTERLEAVED_WEIGHTED_ROUND_ROBIN and fixed pool', () => {
422 const workerChoiceStrategy =
423 WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN
424 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
425 fixedPool
426 )
427 workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy)
428 expect(
429 workerChoiceStrategyContext.workerChoiceStrategies.get(
430 workerChoiceStrategy
431 )
432 ).toBeInstanceOf(InterleavedWeightedRoundRobinWorkerChoiceStrategy)
433 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
434 workerChoiceStrategy
435 )
436 })
437
438 it('Verify that setWorkerChoiceStrategy() works with INTERLEAVED_WEIGHTED_ROUND_ROBIN and dynamic pool', () => {
439 const workerChoiceStrategy =
440 WorkerChoiceStrategies.INTERLEAVED_WEIGHTED_ROUND_ROBIN
441 const workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
442 dynamicPool
443 )
444 workerChoiceStrategyContext.setWorkerChoiceStrategy(workerChoiceStrategy)
445 expect(
446 workerChoiceStrategyContext.workerChoiceStrategies.get(
447 workerChoiceStrategy
448 )
449 ).toBeInstanceOf(InterleavedWeightedRoundRobinWorkerChoiceStrategy)
450 expect(workerChoiceStrategyContext.workerChoiceStrategy).toBe(
451 workerChoiceStrategy
452 )
453 })
454
9e45c2c4 455 it('Verify that worker choice strategy options enable median runtime pool statistics', () => {
2fc5cae3
JB
456 const wwrWorkerChoiceStrategy = WorkerChoiceStrategies.WEIGHTED_ROUND_ROBIN
457 let workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
458 fixedPool,
459 wwrWorkerChoiceStrategy,
460 {
932fc8be 461 runTime: { median: true }
2fc5cae3
JB
462 }
463 )
87de9ff5 464 expect(
932fc8be
JB
465 workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime
466 .average
87de9ff5
JB
467 ).toBe(false)
468 expect(
932fc8be 469 workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime.median
87de9ff5 470 ).toBe(true)
2fc5cae3
JB
471 workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
472 dynamicPool,
473 wwrWorkerChoiceStrategy,
474 {
932fc8be 475 runTime: { median: true }
2fc5cae3
JB
476 }
477 )
87de9ff5 478 expect(
932fc8be
JB
479 workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime
480 .average
87de9ff5
JB
481 ).toBe(false)
482 expect(
932fc8be 483 workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime.median
87de9ff5 484 ).toBe(true)
2fc5cae3
JB
485 const fsWorkerChoiceStrategy = WorkerChoiceStrategies.FAIR_SHARE
486 workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
487 fixedPool,
488 fsWorkerChoiceStrategy,
489 {
932fc8be 490 runTime: { median: true }
2fc5cae3
JB
491 }
492 )
87de9ff5 493 expect(
932fc8be
JB
494 workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime
495 .average
87de9ff5
JB
496 ).toBe(false)
497 expect(
932fc8be 498 workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime.median
87de9ff5 499 ).toBe(true)
2fc5cae3
JB
500 workerChoiceStrategyContext = new WorkerChoiceStrategyContext(
501 dynamicPool,
502 fsWorkerChoiceStrategy,
503 {
932fc8be 504 runTime: { median: true }
2fc5cae3
JB
505 }
506 )
87de9ff5 507 expect(
932fc8be
JB
508 workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime
509 .average
87de9ff5
JB
510 ).toBe(false)
511 expect(
932fc8be 512 workerChoiceStrategyContext.getTaskStatisticsRequirements().runTime.median
87de9ff5 513 ).toBe(true)
2fc5cae3 514 })
40ad1d27 515})