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