Skip to content
This repository has been archived by the owner on May 4, 2018. It is now read-only.

Commit

Permalink
Add two timer ref count tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Sep 27, 2011
1 parent 2c01791 commit 3e5aa06
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 0 deletions.
4 changes: 4 additions & 0 deletions test/test-list.h
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
40 changes: 40 additions & 0 deletions test/test-timer.c
Expand Up @@ -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;
}

0 comments on commit 3e5aa06

Please sign in to comment.