From b5cd78ea05ff214314eeb54fe90350df1dd83b5e Mon Sep 17 00:00:00 2001 From: Bert Belder Date: Wed, 29 May 2013 22:52:06 +0200 Subject: [PATCH] test: reflect new idle semantics in test Update the `idle_starvation` test to verify not only that idle callbacks are called, but also that they are called once per loop iteration. --- test/test-idle.c | 21 +++++++++++++++++++-- 1 file changed, 19 insertions(+), 2 deletions(-) diff --git a/test/test-idle.c b/test/test-idle.c index 4f0294cf..7eea1b83 100644 --- a/test/test-idle.c +++ b/test/test-idle.c @@ -23,10 +23,12 @@ #include "task.h" -static uv_timer_t timer_handle; static uv_idle_t idle_handle; +static uv_check_t check_handle; +static uv_timer_t timer_handle; static int idle_cb_called = 0; +static int check_cb_called = 0; static int timer_cb_called = 0; static int close_cb_called = 0; @@ -41,6 +43,7 @@ static void timer_cb(uv_timer_t* handle, int status) { ASSERT(status == 0); uv_close((uv_handle_t*) &idle_handle, close_cb); + uv_close((uv_handle_t*) &check_handle, close_cb); uv_close((uv_handle_t*) &timer_handle, close_cb); timer_cb_called++; @@ -57,6 +60,15 @@ static void idle_cb(uv_idle_t* handle, int status) { } +static void check_cb(uv_check_t* handle, int status) { + ASSERT(handle == &check_handle); + ASSERT(status == 0); + + check_cb_called++; + LOGF("check_cb %d\n", check_cb_called); +} + + TEST_IMPL(idle_starvation) { int r; @@ -65,6 +77,11 @@ TEST_IMPL(idle_starvation) { r = uv_idle_start(&idle_handle, idle_cb); ASSERT(r == 0); + r = uv_check_init(uv_default_loop(), &check_handle); + ASSERT(r == 0); + r = uv_check_start(&check_handle, check_cb); + ASSERT(r == 0); + r = uv_timer_init(uv_default_loop(), &timer_handle); ASSERT(r == 0); r = uv_timer_start(&timer_handle, timer_cb, 50, 0); @@ -75,7 +92,7 @@ TEST_IMPL(idle_starvation) { ASSERT(idle_cb_called > 0); ASSERT(timer_cb_called == 1); - ASSERT(close_cb_called == 2); + ASSERT(close_cb_called == 3); MAKE_VALGRIND_HAPPY(); return 0;