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