Commit ab0482f0 authored by Dominik Charousset's avatar Dominik Charousset

Add cycle durations in run_dispatch_loop

Giving the `test_coordinator` a cycle duration in `run_dispatch_loop`
allows it to automatically advance the simulated time between calls to
`dispatch`. This simplifies writing unit tests where actors need a
periodic timeout in order to advance.
parent 28bc83cd
......@@ -114,9 +114,10 @@ public:
/// messages.
size_t dispatch();
/// Loops until no job or delayed message remains. Returns the total number of
/// events (first) and dispatched delayed messages (second).
std::pair<size_t, size_t> run_dispatch_loop();
/// Loops until no job or delayed message remains. Returns the total number
/// of events (first) and dispatched delayed messages (second). Advances time
/// by `cycle` between to calls to `dispatch()`.
std::pair<size_t, size_t> run_dispatch_loop(timespan cycle = timespan{0});
template <class F>
void after_next_enqueue(F f) {
......
......@@ -153,17 +153,17 @@ size_t test_coordinator::dispatch() {
return clock().dispatch();
}
std::pair<size_t, size_t> test_coordinator::run_dispatch_loop() {
std::pair<size_t, size_t> res;
size_t i = 0;
do {
std::pair<size_t, size_t> test_coordinator::run_dispatch_loop(timespan cycle) {
std::pair<size_t, size_t> res{0, 0};
for (;;) {
auto x = run();
clock().current_time += cycle;
auto y = dispatch();
if (x + y == 0)
return res;
res.first += x;
res.second += y;
i = x + y;
} while (i > 0);
return res;
}
}
void test_coordinator::inline_next_enqueue() {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment