35 using std::this_thread::sleep_for;
41 using Dur = std::chrono::duration<double, std::milli>;
50 isFast (milliseconds timeoutDelay)
52 return timeoutDelay < Dur{1.2 * EXPECTED_BUILDER_DELAY_ms}
53 and 0ms < timeoutDelay;
57 isSlow (milliseconds timeoutDelay)
59 return timeoutDelay >= Dur{1.2 * EXPECTED_BUILDER_DELAY_ms};
63 isDisabled (milliseconds timeoutDelay)
65 return 0ms == timeoutDelay;
77 bool has_commands_in_queue =
false;
82 return Looper([&](){
return has_commands_in_queue; });
113 verifyWakeupActivity();
114 verifyShutdown_stops_processing();
115 verifyDisabling_stops_processing();
116 verifyBuilderStart();
124 Looper looper = setup.install();
126 CHECK (not looper.isDying());
128 CHECK (not looper.runBuild());
129 CHECK (isDisabled (looper.getTimeout()));
131 setup.has_commands_in_queue =
true;
134 milliseconds timeout = looper.getTimeout();
135 CHECK (10ms < timeout,
"configured idle timeout %2l to short", timeout.count());
136 CHECK (timeout < 800ms,
"configured idle timeout %3l to long", timeout.count());
144 Looper looper = setup.install();
146 CHECK (not looper.isDying());
149 looper.triggerShutdown();
150 CHECK (looper.isDying());
156 verifyWakeupActivity()
159 Looper looper = setup.install();
161 CHECK (not looper.isDying());
165 CHECK (not looper.isWorking());
166 CHECK ( looper.isIdle());
168 setup.has_commands_in_queue =
true;
171 CHECK ( looper.isWorking());
172 CHECK (not looper.isIdle());
175 setup.has_commands_in_queue =
false;
178 CHECK ( looper.useTimeout());
179 CHECK (not looper.isWorking());
180 CHECK (not looper.isIdle());
185 CHECK (not looper.isWorking());
186 CHECK ( looper.isIdle());
189 looper.triggerShutdown();
194 CHECK (not looper.isWorking());
195 CHECK (not looper.isIdle());
200 verifyShutdown_stops_processing()
203 Looper looper = setup.install();
205 CHECK (not looper.isDying());
209 CHECK (not looper.isWorking());
210 CHECK ( looper.isIdle());
212 setup.has_commands_in_queue =
true;
215 CHECK ( looper.isWorking());
216 CHECK (not looper.isIdle());
218 CHECK (not looper.isDying());
220 looper.triggerShutdown();
223 CHECK (not looper.isWorking());
224 CHECK (not looper.isIdle());
226 CHECK ( looper.isDying());
228 setup.has_commands_in_queue =
false;
231 CHECK (not looper.isWorking());
232 CHECK (not looper.isIdle());
234 CHECK ( looper.isDying());
236 setup.has_commands_in_queue =
true;
239 CHECK (not looper.isWorking());
240 CHECK (not looper.isIdle());
242 CHECK ( looper.isDying());
247 verifyDisabling_stops_processing()
250 Looper looper = setup.install();
253 CHECK (not looper.isDisabled());
254 CHECK (not looper.isWorking());
255 CHECK ( looper.isIdle());
257 CHECK (not looper.isDying());
259 setup.has_commands_in_queue =
true;
262 CHECK (not looper.isDisabled());
263 CHECK ( looper.isWorking());
264 CHECK (not looper.isIdle());
266 CHECK (not looper.isDying());
268 looper.enableProcessing(
false);
271 CHECK ( looper.isDisabled());
272 CHECK (not looper.isWorking());
273 CHECK (not looper.isIdle());
275 CHECK (not looper.isDying());
277 setup.has_commands_in_queue =
false;
280 CHECK ( looper.isDisabled());
281 CHECK (not looper.isWorking());
282 CHECK (not looper.isIdle());
284 CHECK (not looper.isDying());
286 setup.has_commands_in_queue =
true;
289 CHECK ( looper.isDisabled());
290 CHECK (not looper.isWorking());
291 CHECK (not looper.isIdle());
293 CHECK (not looper.isDying());
295 looper.enableProcessing();
298 CHECK (not looper.isDisabled());
299 CHECK ( looper.isWorking());
300 CHECK (not looper.isIdle());
302 CHECK (not looper.isDying());
304 looper.enableProcessing(
false);
307 CHECK ( looper.isDisabled());
308 CHECK (not looper.isWorking());
309 CHECK (not looper.isIdle());
311 CHECK (not looper.isDying());
313 looper.triggerShutdown();
316 CHECK ( looper.isDisabled());
317 CHECK (not looper.isWorking());
318 CHECK (not looper.isIdle());
320 CHECK ( looper.isDying());
337 Looper looper = setup.install();
340 CHECK (not looper.isDisabled());
341 CHECK (not looper.isWorking());
342 CHECK (not looper.runBuild());
343 CHECK ( looper.isIdle());
345 setup.has_commands_in_queue =
true;
348 CHECK (not looper.isDisabled());
349 CHECK ( looper.isWorking());
350 CHECK (not looper.runBuild());
351 CHECK (not looper.isIdle());
356 CHECK (not looper.isDisabled());
357 CHECK ( looper.isWorking());
358 CHECK (not looper.runBuild());
359 CHECK (not looper.isIdle());
361 CHECK (isSlow (looper.getTimeout()));
367 CHECK (not looper.isDisabled());
368 CHECK ( looper.isWorking());
369 CHECK (not looper.runBuild());
370 CHECK (not looper.isIdle());
375 CHECK (not looper.isDisabled());
376 CHECK ( looper.isWorking());
377 CHECK ( looper.runBuild());
378 CHECK (not looper.isIdle());
383 CHECK (not looper.isDisabled());
384 CHECK ( looper.isWorking());
385 CHECK (not looper.runBuild());
386 CHECK (not looper.isIdle());
389 setup.has_commands_in_queue =
false;
392 CHECK (not looper.isDisabled());
393 CHECK (not looper.isWorking());
394 CHECK ( looper.runBuild());
395 CHECK (not looper.isIdle());
397 CHECK (isFast (looper.getTimeout()));
404 CHECK (not looper.isDisabled());
405 CHECK (not looper.isWorking());
406 CHECK (not looper.runBuild());
407 CHECK ( looper.isIdle());
409 CHECK (isDisabled(looper.getTimeout()));
412 setup.has_commands_in_queue =
true;
415 CHECK (not looper.isDisabled());
416 CHECK ( looper.isWorking());
417 CHECK (not looper.runBuild());
418 CHECK (not looper.isIdle());
420 setup.has_commands_in_queue =
false;
424 CHECK (not looper.isDisabled());
425 CHECK (not looper.isWorking());
426 CHECK ( looper.runBuild());
427 CHECK (not looper.isIdle());
429 CHECK (isFast (looper.getTimeout()));
432 looper.enableProcessing(
false);
435 CHECK ( looper.isDisabled());
436 CHECK (not looper.isWorking());
437 CHECK (not looper.runBuild());
438 CHECK (not looper.isIdle());
440 CHECK (isDisabled (looper.getTimeout()));
443 looper.enableProcessing(
true);
446 CHECK (not looper.isDisabled());
447 CHECK (not looper.isWorking());
448 CHECK ( looper.runBuild());
449 CHECK (not looper.isIdle());
451 CHECK (isFast (looper.getTimeout()));
453 looper.enableProcessing(
false);
457 CHECK ( looper.isDisabled());
458 CHECK (not looper.isWorking());
459 CHECK (not looper.runBuild());
460 CHECK (not looper.isIdle());
462 CHECK (isDisabled (looper.getTimeout()));
465 looper.enableProcessing(
true);
467 CHECK (isFast (looper.getTimeout()));
470 CHECK (not looper.isDisabled());
471 CHECK (not looper.isWorking());
472 CHECK ( looper.runBuild());
473 CHECK (not looper.isIdle());
478 CHECK (not looper.isDisabled());
479 CHECK (not looper.isWorking());
480 CHECK (not looper.runBuild());
481 CHECK ( looper.isIdle());
483 CHECK (isDisabled (looper.getTimeout()));
486 setup.has_commands_in_queue =
true;
490 CHECK (not looper.isDisabled());
491 CHECK ( looper.isWorking());
492 CHECK (not looper.runBuild());
493 CHECK (not looper.isIdle());
495 looper.triggerShutdown();
498 CHECK ( looper.isDisabled());
499 CHECK (not looper.isWorking());
500 CHECK (not looper.runBuild());
501 CHECK (not looper.isIdle());
503 CHECK (isDisabled (looper.getTimeout()));
506 setup.has_commands_in_queue =
false;
509 CHECK (isDisabled (looper.getTimeout()));
513 CHECK ( looper.isDisabled());
514 CHECK (not looper.isWorking());
515 CHECK (not looper.runBuild());
516 CHECK (not looper.isIdle());
Steam-Layer implementation namespace root.
bool shallLoop() const
state fusion to control looping
bool requireAction()
state fusion to control (timed) wait
Implementation building block of SteamDispatcher to control waiting and timing.
void verifyBuilderStart()
const uint EXPECTED_BUILDER_DELAY_ms
Simple test class runner.
void markStateProcessed()
invoking this function signals that all consequences of past state changes have been processed and ar...
auto setup(FUN &&workFun)
Helper: setup a Worker-Pool configuration for the test.
Encapsulated control logic for the session thread loop.