xref: /openbmc/sdbusplus/test/async/timer.cpp (revision 435eb1bd6ba1ec0943f599f18c67d7206981002b)
1 #include <sdbusplus/async.hpp>
2 
3 #include <chrono>
4 
5 #include <gtest/gtest.h>
6 
7 using namespace std::literals;
8 
9 TEST(Timer, DelaySome)
10 {
11     static constexpr auto timeout = 500ms;
12 
13     sdbusplus::async::context ctx;
14 
15     auto start = std::chrono::steady_clock::now();
16 
17     ctx.run(sdbusplus::async::sleep_for(ctx, timeout) |
18             std::execution::then([&ctx]() { ctx.request_stop(); }));
19 
20     auto stop = std::chrono::steady_clock::now();
21 
22     EXPECT_GT(stop - start, timeout);
23     EXPECT_LT(stop - start, timeout * 2);
24 }
25