timer tests to work on unix

This commit is contained in:
Ryan Dahl 2011-05-18 22:23:17 -07:00
parent 103099e175
commit 9c2dd6bea9
2 changed files with 17 additions and 4 deletions

View File

@ -76,12 +76,18 @@ static void repeat_2_cb(uv_handle_t* handle, int status) {
repeat_2_cb_called++;
if (!uv_is_active(handle)) {
ASSERT(uv_timer_get_repeat(handle) == 0);
if (uv_timer_get_repeat(handle) == 0) {
/* XXX Libev does considers the timer active here.
* I'm not saying it must be this way, but we should consider what
* exactly the semantics of uv_is_active() should be. Is a timer that's
* initialized but stopped active?
*/
ASSERT(uv_is_active(handle));
uv_close(handle);
return;
}
LOGF("uv_timer_get_repeat %ld ms\n", (long int)uv_timer_get_repeat(handle));
ASSERT(uv_timer_get_repeat(handle) == 100);
/* This shouldn't take effect immediately. */
@ -123,8 +129,10 @@ TEST_IMPL(timer_again) {
uv_timer_set_repeat(&repeat_1, 50);
ASSERT(uv_timer_get_repeat(&repeat_1) == 50);
/* Start another repeating timer. It'll be again()ed by the repeat_1 so */
/* it should not time out until repeat_1 stops. */
/*
* Start another repeating timer. It'll be again()ed by the repeat_1 so
* it should not time out until repeat_1 stops.
*/
r = uv_timer_init(&repeat_2, close_cb, NULL);
ASSERT(r == 0);
r = uv_timer_start(&repeat_2, repeat_2_cb, 100, 100);

View File

@ -1177,6 +1177,11 @@ int uv_timer_stop(uv_handle_t* handle) {
int uv_timer_again(uv_handle_t* handle) {
if (!ev_is_active(&handle->timer_watcher)) {
uv_err_new(handle, EINVAL);
return -1;
}
ev_timer_again(EV_DEFAULT_UC_ &handle->timer_watcher);
return 0;
}