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: ...@@ -114,9 +114,10 @@ public:
/// messages. /// messages.
size_t dispatch(); size_t dispatch();
/// Loops until no job or delayed message remains. Returns the total number of /// Loops until no job or delayed message remains. Returns the total number
/// events (first) and dispatched delayed messages (second). /// of events (first) and dispatched delayed messages (second). Advances time
std::pair<size_t, size_t> run_dispatch_loop(); /// by `cycle` between to calls to `dispatch()`.
std::pair<size_t, size_t> run_dispatch_loop(timespan cycle = timespan{0});
template <class F> template <class F>
void after_next_enqueue(F f) { void after_next_enqueue(F f) {
......
...@@ -153,17 +153,17 @@ size_t test_coordinator::dispatch() { ...@@ -153,17 +153,17 @@ size_t test_coordinator::dispatch() {
return clock().dispatch(); return clock().dispatch();
} }
std::pair<size_t, size_t> test_coordinator::run_dispatch_loop() { std::pair<size_t, size_t> test_coordinator::run_dispatch_loop(timespan cycle) {
std::pair<size_t, size_t> res; std::pair<size_t, size_t> res{0, 0};
size_t i = 0; for (;;) {
do {
auto x = run(); auto x = run();
clock().current_time += cycle;
auto y = dispatch(); auto y = dispatch();
if (x + y == 0)
return res;
res.first += x; res.first += x;
res.second += y; res.second += y;
i = x + y; }
} while (i > 0);
return res;
} }
void test_coordinator::inline_next_enqueue() { 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