|
@ -28,8 +28,10 @@ static int once_close_cb_called = 0; |
|
|
static int repeat_cb_called = 0; |
|
|
static int repeat_cb_called = 0; |
|
|
static int repeat_close_cb_called = 0; |
|
|
static int repeat_close_cb_called = 0; |
|
|
static int order_cb_called = 0; |
|
|
static int order_cb_called = 0; |
|
|
|
|
|
|
|
|
static uint64_t start_time; |
|
|
static uint64_t start_time; |
|
|
|
|
|
static uv_timer_t tiny_timer; |
|
|
|
|
|
static uv_timer_t huge_timer1; |
|
|
|
|
|
static uv_timer_t huge_timer2; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void once_close_cb(uv_handle_t* handle) { |
|
|
static void once_close_cb(uv_handle_t* handle) { |
|
@ -156,6 +158,18 @@ TEST_IMPL(timer_start_twice) { |
|
|
} |
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_IMPL(timer_init) { |
|
|
|
|
|
uv_timer_t handle; |
|
|
|
|
|
|
|
|
|
|
|
ASSERT(0 == uv_timer_init(uv_default_loop(), &handle)); |
|
|
|
|
|
ASSERT(0 == uv_timer_get_repeat(&handle)); |
|
|
|
|
|
ASSERT(!uv_is_active((uv_handle_t*)&handle)); |
|
|
|
|
|
|
|
|
|
|
|
MAKE_VALGRIND_HAPPY(); |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void order_cb_a(uv_timer_t *handle, int status) { |
|
|
static void order_cb_a(uv_timer_t *handle, int status) { |
|
|
ASSERT(order_cb_called++ == *(int*)handle->data); |
|
|
ASSERT(order_cb_called++ == *(int*)handle->data); |
|
|
} |
|
|
} |
|
@ -200,5 +214,53 @@ TEST_IMPL(timer_order) { |
|
|
|
|
|
|
|
|
ASSERT(order_cb_called == 2); |
|
|
ASSERT(order_cb_called == 2); |
|
|
|
|
|
|
|
|
|
|
|
MAKE_VALGRIND_HAPPY(); |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void tiny_timer_cb(uv_timer_t* handle, int status) { |
|
|
|
|
|
ASSERT(handle == &tiny_timer); |
|
|
|
|
|
uv_close((uv_handle_t*) &tiny_timer, NULL); |
|
|
|
|
|
uv_close((uv_handle_t*) &huge_timer1, NULL); |
|
|
|
|
|
uv_close((uv_handle_t*) &huge_timer2, NULL); |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_IMPL(timer_huge_timeout) { |
|
|
|
|
|
ASSERT(0 == uv_timer_init(uv_default_loop(), &tiny_timer)); |
|
|
|
|
|
ASSERT(0 == uv_timer_init(uv_default_loop(), &huge_timer1)); |
|
|
|
|
|
ASSERT(0 == uv_timer_init(uv_default_loop(), &huge_timer2)); |
|
|
|
|
|
ASSERT(0 == uv_timer_start(&tiny_timer, tiny_timer_cb, 1, 0)); |
|
|
|
|
|
ASSERT(0 == uv_timer_start(&huge_timer1, tiny_timer_cb, 0xffffffffffffLL, 0)); |
|
|
|
|
|
ASSERT(0 == uv_timer_start(&huge_timer2, tiny_timer_cb, (uint64_t) -1, 0)); |
|
|
|
|
|
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); |
|
|
|
|
|
MAKE_VALGRIND_HAPPY(); |
|
|
|
|
|
return 0; |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static void huge_repeat_cb(uv_timer_t* handle, int status) { |
|
|
|
|
|
static int ncalls; |
|
|
|
|
|
|
|
|
|
|
|
if (ncalls == 0) |
|
|
|
|
|
ASSERT(handle == &huge_timer1); |
|
|
|
|
|
else |
|
|
|
|
|
ASSERT(handle == &tiny_timer); |
|
|
|
|
|
|
|
|
|
|
|
if (++ncalls == 10) { |
|
|
|
|
|
uv_close((uv_handle_t*) &tiny_timer, NULL); |
|
|
|
|
|
uv_close((uv_handle_t*) &huge_timer1, NULL); |
|
|
|
|
|
} |
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
TEST_IMPL(timer_huge_repeat) { |
|
|
|
|
|
ASSERT(0 == uv_timer_init(uv_default_loop(), &tiny_timer)); |
|
|
|
|
|
ASSERT(0 == uv_timer_init(uv_default_loop(), &huge_timer1)); |
|
|
|
|
|
ASSERT(0 == uv_timer_start(&tiny_timer, huge_repeat_cb, 2, 2)); |
|
|
|
|
|
ASSERT(0 == uv_timer_start(&huge_timer1, huge_repeat_cb, 1, (uint64_t) -1)); |
|
|
|
|
|
ASSERT(0 == uv_run(uv_default_loop(), UV_RUN_DEFAULT)); |
|
|
|
|
|
MAKE_VALGRIND_HAPPY(); |
|
|
return 0; |
|
|
return 0; |
|
|
} |
|
|
} |
|
|