0
0
mirror of https://github.com/zeromq/libzmq.git synced 2025-01-14 01:37:56 +08:00

problem: timers test is flapping on windows

This commit is contained in:
Doron Somech 2016-05-05 14:17:35 +03:00
parent a747f72450
commit be741f604a

View File

@ -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;