Skip to content

Commit

Permalink
Add test for trampoline that sleeps current thread for future job.
Browse files Browse the repository at this point in the history
  • Loading branch information
tcw165 committed Sep 8, 2022
1 parent 7277465 commit d05ef1b
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions src/tests/test_schedulers.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -621,6 +621,28 @@ SCENARIO("trampoline scheduler regards unsubscribed subscription")
}
}

SCENARIO("trampoline respects the given time-point")
{
auto sub = rpp::composite_subscription{};
auto worker = rpp::schedulers::trampoline::create_worker(sub);

auto delay = std::chrono::duration_cast<rpp::schedulers::duration>(std::chrono::seconds{1});

WHEN("schedule at future")
{
auto now = rpp::schedulers::clock_type::now();
auto future = now + delay;
worker.schedule(future, [&]() -> rpp::schedulers::optional_duration
{
THEN("this thread should sleep for the delay duration")
{
CHECK(rpp::schedulers::clock_type::now() >= now + delay);
}
return std::nullopt;
});
}
}

SCENARIO("RunLoop scheduler dispatches tasks only manually")
{
GIVEN("run loop scheduler")
Expand Down

0 comments on commit d05ef1b

Please sign in to comment.