blob: 7aee04f9367353ee8dd0851e2e06146636f9fe39 [file] [log] [blame]
Patrick Williams435eb1b2022-09-16 16:22:07 -05001#include <sdbusplus/async.hpp>
2
3#include <chrono>
4
5#include <gtest/gtest.h>
6
7using namespace std::literals;
8
9TEST(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 Williams3c242ba2022-09-23 09:51:55 -050017 ctx.spawn(sdbusplus::async::sleep_for(ctx, timeout) |
Patrick Williams5e7ef082023-01-05 11:08:53 -060018 stdexec::then([&ctx]() { ctx.request_stop(); }));
Patrick Williams3c242ba2022-09-23 09:51:55 -050019 ctx.run();
Patrick Williams435eb1b2022-09-16 16:22:07 -050020
21 auto stop = std::chrono::steady_clock::now();
22
23 EXPECT_GT(stop - start, timeout);
Patrick Williams6ea246a2022-10-14 07:58:15 -050024 EXPECT_LT(stop - start, timeout * 3);
Patrick Williams435eb1b2022-09-16 16:22:07 -050025}