MCPcopy Create free account
hub / github.com/boostorg/asio / system_timer_test

Function system_timer_test

test/system_timer.cpp:79–222  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

77}
78
79void 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();

Callers

nothing calls this directly

Calls 10

restartMethod · 0.80
nowFunction · 0.70
bindFunction · 0.50
get_executorMethod · 0.45
waitMethod · 0.45
expires_atMethod · 0.45
expiryMethod · 0.45
expires_afterMethod · 0.45
async_waitMethod · 0.45
runMethod · 0.45

Tested by

no test coverage detected