Add tcp reference count tests

This commit is contained in:
Ryan Dahl 2011-09-26 22:51:08 -07:00
parent 3e5aa06c49
commit 2ebb2272c3
2 changed files with 55 additions and 0 deletions

View File

@ -22,6 +22,8 @@
TEST_DECLARE (tty)
TEST_DECLARE (tcp_ping_pong)
TEST_DECLARE (tcp_ping_pong_v6)
TEST_DECLARE (tcp_ref)
TEST_DECLARE (tcp_ref2)
TEST_DECLARE (pipe_ping_pong)
TEST_DECLARE (delayed_accept)
TEST_DECLARE (tcp_writealot)
@ -106,6 +108,12 @@ HELPER_DECLARE (pipe_echo_server)
TASK_LIST_START
TEST_ENTRY (tty)
TEST_ENTRY (tcp_ref)
TEST_ENTRY (tcp_ref2)
TEST_HELPER (tcp_ref2, tcp4_echo_server)
TEST_ENTRY (tcp_ping_pong)
TEST_HELPER (tcp_ping_pong, tcp4_echo_server)

View File

@ -127,3 +127,50 @@ TEST_IMPL(tcp_close) {
return 0;
}
TEST_IMPL(tcp_ref) {
uv_tcp_t never;
int r;
/* A tcp just initialized should count as one reference. */
r = uv_tcp_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;
}
static void never_cb(uv_connect_t* conn_req, int status) {
FATAL("never_cb should never be called");
}
TEST_IMPL(tcp_ref2) {
uv_tcp_t never;
int r;
/* A tcp just initialized should count as one reference. */
r = uv_tcp_init(uv_default_loop(), &never);
ASSERT(r == 0);
r = uv_tcp_connect(&connect_req,
&never,
uv_ip4_addr("127.0.0.1", TEST_PORT),
never_cb);
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;
}