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