Add two timer ref count tests
This commit is contained in:
parent
2c0179197f
commit
3e5aa06c49
@ -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)
|
||||
|
||||
|
||||
@ -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;
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user