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