Commit be741f60 authored by Doron Somech's avatar Doron Somech

problem: timers test is flapping on windows

parent a747f724
......@@ -46,6 +46,19 @@ void handler (int timer_id, void* arg)
*((bool *)arg) = true;
}
int sleep_and_execute(void *timers_)
{
int timeout = zmq_timers_timeout (timers_);
// Sleep methods are inaccurate, so we sleep in a loop until time arrived
while (timeout > 0) {
sleep_ (timeout);
timeout = zmq_timers_timeout(timers_);
}
return zmq_timers_execute(timers_);
}
int main (void)
{
setup_test_environment ();
......@@ -69,9 +82,8 @@ int main (void)
assert (rc == 0);
assert (!timer_invoked);
// Wait until the end
sleep_ (zmq_timers_timeout (timers));
rc = zmq_timers_execute (timers);
// Wait until the end
rc = sleep_and_execute (timers);
assert (rc == 0);
assert (timer_invoked);
timer_invoked = false;
......@@ -91,16 +103,14 @@ int main (void)
assert (!timer_invoked);
// Wait until the end
sleep_ (zmq_timers_timeout (timers));
rc = zmq_timers_execute (timers);
rc = sleep_and_execute(timers);
assert (rc == 0);
assert (timer_invoked);
timer_invoked = false;
// reschedule
zmq_timers_set_interval (timers, timer_id, 50);
sleep_ (51);
rc = zmq_timers_execute (timers);
rc = sleep_and_execute(timers);
assert (rc == 0);
assert (timer_invoked);
timer_invoked = false;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment