Patrick Williams | 435eb1b | 2022-09-16 16:22:07 -0500 | [diff] [blame] | 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 | |
Patrick Williams | 3c242ba | 2022-09-23 09:51:55 -0500 | [diff] [blame] | 17 | ctx.spawn(sdbusplus::async::sleep_for(ctx, timeout) | |
| 18 | std::execution::then([&ctx]() { ctx.request_stop(); })); |
| 19 | ctx.run(); |
Patrick Williams | 435eb1b | 2022-09-16 16:22:07 -0500 | [diff] [blame] | 20 | |
| 21 | auto stop = std::chrono::steady_clock::now(); |
| 22 | |
| 23 | EXPECT_GT(stop - start, timeout); |
Patrick Williams | 6ea246a | 2022-10-14 07:58:15 -0500 | [diff] [blame^] | 24 | EXPECT_LT(stop - start, timeout * 3); |
Patrick Williams | 435eb1b | 2022-09-16 16:22:07 -0500 | [diff] [blame] | 25 | } |