diff --git a/test/test-list.h b/test/test-list.h index bf376e3914..267912284c 100644 --- a/test/test-list.h +++ b/test/test-list.h @@ -52,6 +52,8 @@ TEST_DECLARE (connection_fail_doesnt_auto_close) TEST_DECLARE (shutdown_eof) TEST_DECLARE (callback_stack) TEST_DECLARE (timer) +TEST_DECLARE (timer_ref) +TEST_DECLARE (timer_ref2) TEST_DECLARE (timer_again) TEST_DECLARE (idle_starvation) TEST_DECLARE (loop_handles) @@ -154,6 +156,8 @@ TASK_LIST_START TEST_HELPER (callback_stack, tcp4_echo_server) TEST_ENTRY (timer) + TEST_ENTRY (timer_ref) + TEST_ENTRY (timer_ref2) TEST_ENTRY (timer_again) diff --git a/test/test-timer.c b/test/test-timer.c index 17bcb84b77..87235a51bc 100644 --- a/test/test-timer.c +++ b/test/test-timer.c @@ -130,3 +130,43 @@ TEST_IMPL(timer) { return 0; } + + +TEST_IMPL(timer_ref) { + uv_timer_t never; + int r; + + /* A timer just initialized should count as one reference. */ + r = uv_timer_init(uv_default_loop(), &never); + ASSERT(r == 0); + + /* One unref should set the loop ref count to zero. */ + uv_unref(uv_default_loop()); + + /* Therefore this does not block */ + uv_run(uv_default_loop()); + + return 0; +} + + +TEST_IMPL(timer_ref2) { + uv_timer_t never; + int r; + + /* A timer just initialized should count as one reference. */ + r = uv_timer_init(uv_default_loop(), &never); + ASSERT(r == 0); + + /* We start the timer, this should not effect the ref count. */ + r = uv_timer_start(&never, never_cb, 1000, 1000); + ASSERT(r == 0); + + /* One unref should set the loop ref count to zero. */ + uv_unref(uv_default_loop()); + + /* Therefore this does not block */ + uv_run(uv_default_loop()); + + return 0; +}