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