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