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) ...@@ -46,6 +46,19 @@ void handler (int timer_id, void* arg)
*((bool *)arg) = true; *((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) int main (void)
{ {
setup_test_environment (); setup_test_environment ();
...@@ -70,8 +83,7 @@ int main (void) ...@@ -70,8 +83,7 @@ int main (void)
assert (!timer_invoked); assert (!timer_invoked);
// Wait until the end // Wait until the end
sleep_ (zmq_timers_timeout (timers)); rc = sleep_and_execute (timers);
rc = zmq_timers_execute (timers);
assert (rc == 0); assert (rc == 0);
assert (timer_invoked); assert (timer_invoked);
timer_invoked = false; timer_invoked = false;
...@@ -91,16 +103,14 @@ int main (void) ...@@ -91,16 +103,14 @@ int main (void)
assert (!timer_invoked); assert (!timer_invoked);
// Wait until the end // Wait until the end
sleep_ (zmq_timers_timeout (timers)); rc = sleep_and_execute(timers);
rc = zmq_timers_execute (timers);
assert (rc == 0); assert (rc == 0);
assert (timer_invoked); assert (timer_invoked);
timer_invoked = false; timer_invoked = false;
// reschedule // reschedule
zmq_timers_set_interval (timers, timer_id, 50); zmq_timers_set_interval (timers, timer_id, 50);
sleep_ (51); rc = sleep_and_execute(timers);
rc = zmq_timers_execute (timers);
assert (rc == 0); assert (rc == 0);
assert (timer_invoked); assert (timer_invoked);
timer_invoked = false; 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