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