Skip to content

Commit

Permalink
test: reflect new idle semantics in test
Browse files Browse the repository at this point in the history
Update the `idle_starvation` test to verify not only that idle callbacks
are called, but also that they are called once per loop iteration.
  • Loading branch information
piscisaureus committed May 29, 2013
1 parent bc56a4e commit b5cd78e
Showing 1 changed file with 19 additions and 2 deletions.
21 changes: 19 additions & 2 deletions test/test-idle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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++;
Expand All @@ -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;

Expand All @@ -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);
Expand All @@ -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;
Expand Down

0 comments on commit b5cd78e

Please sign in to comment.