| 77 | } |
| 78 | |
| 79 | void system_timer_test() |
| 80 | { |
| 81 | using boost::asio::chrono::seconds; |
| 82 | using boost::asio::chrono::microseconds; |
| 83 | using bindns::placeholders::_1; |
| 84 | using bindns::placeholders::_2; |
| 85 | |
| 86 | boost::asio::io_context ioc; |
| 87 | const boost::asio::io_context::executor_type ioc_ex = ioc.get_executor(); |
| 88 | int count = 0; |
| 89 | |
| 90 | boost::asio::system_timer::time_point start = now(); |
| 91 | |
| 92 | boost::asio::system_timer t1(ioc, seconds(1)); |
| 93 | t1.wait(); |
| 94 | |
| 95 | // The timer must block until after its expiry time. |
| 96 | boost::asio::system_timer::time_point end = now(); |
| 97 | boost::asio::system_timer::time_point expected_end = start + seconds(1); |
| 98 | BOOST_ASIO_CHECK(expected_end < end || expected_end == end); |
| 99 | |
| 100 | start = now(); |
| 101 | |
| 102 | boost::asio::system_timer t2(ioc_ex, seconds(1) + microseconds(500000)); |
| 103 | t2.wait(); |
| 104 | |
| 105 | // The timer must block until after its expiry time. |
| 106 | end = now(); |
| 107 | expected_end = start + seconds(1) + microseconds(500000); |
| 108 | BOOST_ASIO_CHECK(expected_end < end || expected_end == end); |
| 109 | |
| 110 | t2.expires_at(t2.expiry() + seconds(1)); |
| 111 | t2.wait(); |
| 112 | |
| 113 | // The timer must block until after its expiry time. |
| 114 | end = now(); |
| 115 | expected_end += seconds(1); |
| 116 | BOOST_ASIO_CHECK(expected_end < end || expected_end == end); |
| 117 | |
| 118 | start = now(); |
| 119 | |
| 120 | t2.expires_after(seconds(1) + microseconds(200000)); |
| 121 | t2.wait(); |
| 122 | |
| 123 | // The timer must block until after its expiry time. |
| 124 | end = now(); |
| 125 | expected_end = start + seconds(1) + microseconds(200000); |
| 126 | BOOST_ASIO_CHECK(expected_end < end || expected_end == end); |
| 127 | |
| 128 | start = now(); |
| 129 | |
| 130 | boost::asio::system_timer t3(ioc, seconds(5)); |
| 131 | t3.async_wait(bindns::bind(increment, &count)); |
| 132 | |
| 133 | // No completions can be delivered until run() is called. |
| 134 | BOOST_ASIO_CHECK(count == 0); |
| 135 | |
| 136 | ioc.run(); |
nothing calls this directly
no test coverage detected