26 using std::this_thread::sleep_for;
32 using Dur = std::chrono::duration<double, std::milli>;
41 isFast (milliseconds timeoutDelay)
43 return timeoutDelay < Dur{1.2 * EXPECTED_BUILDER_DELAY_ms}
44 and 0ms < timeoutDelay;
48 isSlow (milliseconds timeoutDelay)
50 return timeoutDelay >= Dur{1.2 * EXPECTED_BUILDER_DELAY_ms};
54 isDisabled (milliseconds timeoutDelay)
56 return 0ms == timeoutDelay;
68 bool has_commands_in_queue =
false;
73 return Looper([&](){
return has_commands_in_queue; });
104 verifyWakeupActivity();
105 verifyShutdown_stops_processing();
106 verifyDisabling_stops_processing();
107 verifyBuilderStart();
115 Looper looper = setup.install();
117 CHECK (not looper.isDying());
119 CHECK (not looper.runBuild());
120 CHECK (isDisabled (looper.getTimeout()));
122 setup.has_commands_in_queue =
true;
125 milliseconds timeout = looper.getTimeout();
126 CHECK (10ms < timeout,
"configured idle timeout %2l to short", timeout.count());
127 CHECK (timeout < 800ms,
"configured idle timeout %3l to long", timeout.count());
135 Looper looper = setup.install();
137 CHECK (not looper.isDying());
140 looper.triggerShutdown();
141 CHECK (looper.isDying());
147 verifyWakeupActivity()
150 Looper looper = setup.install();
152 CHECK (not looper.isDying());
156 CHECK (not looper.isWorking());
157 CHECK ( looper.isIdle());
159 setup.has_commands_in_queue =
true;
162 CHECK ( looper.isWorking());
163 CHECK (not looper.isIdle());
166 setup.has_commands_in_queue =
false;
169 CHECK ( looper.useTimeout());
170 CHECK (not looper.isWorking());
171 CHECK (not looper.isIdle());
176 CHECK (not looper.isWorking());
177 CHECK ( looper.isIdle());
180 looper.triggerShutdown();
185 CHECK (not looper.isWorking());
186 CHECK (not looper.isIdle());
191 verifyShutdown_stops_processing()
194 Looper looper = setup.install();
196 CHECK (not looper.isDying());
200 CHECK (not looper.isWorking());
201 CHECK ( looper.isIdle());
203 setup.has_commands_in_queue =
true;
206 CHECK ( looper.isWorking());
207 CHECK (not looper.isIdle());
209 CHECK (not looper.isDying());
211 looper.triggerShutdown();
214 CHECK (not looper.isWorking());
215 CHECK (not looper.isIdle());
217 CHECK ( looper.isDying());
219 setup.has_commands_in_queue =
false;
222 CHECK (not looper.isWorking());
223 CHECK (not looper.isIdle());
225 CHECK ( looper.isDying());
227 setup.has_commands_in_queue =
true;
230 CHECK (not looper.isWorking());
231 CHECK (not looper.isIdle());
233 CHECK ( looper.isDying());
238 verifyDisabling_stops_processing()
241 Looper looper = setup.install();
244 CHECK (not looper.isDisabled());
245 CHECK (not looper.isWorking());
246 CHECK ( looper.isIdle());
248 CHECK (not looper.isDying());
250 setup.has_commands_in_queue =
true;
253 CHECK (not looper.isDisabled());
254 CHECK ( looper.isWorking());
255 CHECK (not looper.isIdle());
257 CHECK (not looper.isDying());
259 looper.enableProcessing(
false);
262 CHECK ( looper.isDisabled());
263 CHECK (not looper.isWorking());
264 CHECK (not looper.isIdle());
266 CHECK (not looper.isDying());
268 setup.has_commands_in_queue =
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 =
true;
280 CHECK ( looper.isDisabled());
281 CHECK (not looper.isWorking());
282 CHECK (not looper.isIdle());
284 CHECK (not looper.isDying());
286 looper.enableProcessing();
289 CHECK (not looper.isDisabled());
290 CHECK ( looper.isWorking());
291 CHECK (not looper.isIdle());
293 CHECK (not looper.isDying());
295 looper.enableProcessing(
false);
298 CHECK ( looper.isDisabled());
299 CHECK (not looper.isWorking());
300 CHECK (not looper.isIdle());
302 CHECK (not looper.isDying());
304 looper.triggerShutdown();
307 CHECK ( looper.isDisabled());
308 CHECK (not looper.isWorking());
309 CHECK (not looper.isIdle());
311 CHECK ( looper.isDying());
328 Looper looper = setup.install();
331 CHECK (not looper.isDisabled());
332 CHECK (not looper.isWorking());
333 CHECK (not looper.runBuild());
334 CHECK ( looper.isIdle());
336 setup.has_commands_in_queue =
true;
339 CHECK (not looper.isDisabled());
340 CHECK ( looper.isWorking());
341 CHECK (not looper.runBuild());
342 CHECK (not looper.isIdle());
347 CHECK (not looper.isDisabled());
348 CHECK ( looper.isWorking());
349 CHECK (not looper.runBuild());
350 CHECK (not looper.isIdle());
352 CHECK (isSlow (looper.getTimeout()));
358 CHECK (not looper.isDisabled());
359 CHECK ( looper.isWorking());
360 CHECK (not looper.runBuild());
361 CHECK (not looper.isIdle());
366 CHECK (not looper.isDisabled());
367 CHECK ( looper.isWorking());
368 CHECK ( looper.runBuild());
369 CHECK (not looper.isIdle());
374 CHECK (not looper.isDisabled());
375 CHECK ( looper.isWorking());
376 CHECK (not looper.runBuild());
377 CHECK (not looper.isIdle());
380 setup.has_commands_in_queue =
false;
383 CHECK (not looper.isDisabled());
384 CHECK (not looper.isWorking());
385 CHECK ( looper.runBuild());
386 CHECK (not looper.isIdle());
388 CHECK (isFast (looper.getTimeout()));
395 CHECK (not looper.isDisabled());
396 CHECK (not looper.isWorking());
397 CHECK (not looper.runBuild());
398 CHECK ( looper.isIdle());
400 CHECK (isDisabled(looper.getTimeout()));
403 setup.has_commands_in_queue =
true;
406 CHECK (not looper.isDisabled());
407 CHECK ( looper.isWorking());
408 CHECK (not looper.runBuild());
409 CHECK (not looper.isIdle());
411 setup.has_commands_in_queue =
false;
415 CHECK (not looper.isDisabled());
416 CHECK (not looper.isWorking());
417 CHECK ( looper.runBuild());
418 CHECK (not looper.isIdle());
420 CHECK (isFast (looper.getTimeout()));
423 looper.enableProcessing(
false);
426 CHECK ( looper.isDisabled());
427 CHECK (not looper.isWorking());
428 CHECK (not looper.runBuild());
429 CHECK (not looper.isIdle());
431 CHECK (isDisabled (looper.getTimeout()));
434 looper.enableProcessing(
true);
437 CHECK (not looper.isDisabled());
438 CHECK (not looper.isWorking());
439 CHECK ( looper.runBuild());
440 CHECK (not looper.isIdle());
442 CHECK (isFast (looper.getTimeout()));
444 looper.enableProcessing(
false);
448 CHECK ( looper.isDisabled());
449 CHECK (not looper.isWorking());
450 CHECK (not looper.runBuild());
451 CHECK (not looper.isIdle());
453 CHECK (isDisabled (looper.getTimeout()));
456 looper.enableProcessing(
true);
458 CHECK (isFast (looper.getTimeout()));
461 CHECK (not looper.isDisabled());
462 CHECK (not looper.isWorking());
463 CHECK ( looper.runBuild());
464 CHECK (not looper.isIdle());
469 CHECK (not looper.isDisabled());
470 CHECK (not looper.isWorking());
471 CHECK (not looper.runBuild());
472 CHECK ( looper.isIdle());
474 CHECK (isDisabled (looper.getTimeout()));
477 setup.has_commands_in_queue =
true;
481 CHECK (not looper.isDisabled());
482 CHECK ( looper.isWorking());
483 CHECK (not looper.runBuild());
484 CHECK (not looper.isIdle());
486 looper.triggerShutdown();
489 CHECK ( looper.isDisabled());
490 CHECK (not looper.isWorking());
491 CHECK (not looper.runBuild());
492 CHECK (not looper.isIdle());
494 CHECK (isDisabled (looper.getTimeout()));
497 setup.has_commands_in_queue =
false;
500 CHECK (isDisabled (looper.getTimeout()));
504 CHECK ( looper.isDisabled());
505 CHECK (not looper.isWorking());
506 CHECK (not looper.runBuild());
507 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
Simplistic 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.