diff --git a/test/test-list.h b/test/test-list.h index 13713717..033be382 100644 --- a/test/test-list.h +++ b/test/test-list.h @@ -79,12 +79,16 @@ TEST_DECLARE (fs_event_ref) TEST_DECLARE (tcp_ref) TEST_DECLARE (tcp_ref2) TEST_DECLARE (tcp_ref3) +TEST_DECLARE (tcp_ref4) +TEST_DECLARE (tcp_ref5) TEST_DECLARE (udp_ref) TEST_DECLARE (udp_ref2) TEST_DECLARE (udp_ref3) TEST_DECLARE (pipe_ref) TEST_DECLARE (pipe_ref2) TEST_DECLARE (pipe_ref3) +TEST_DECLARE (pipe_ref4) +TEST_DECLARE (pipe_ref5) TEST_DECLARE (process_ref) TEST_DECLARE (async) TEST_DECLARE (get_currentexe) @@ -228,6 +232,10 @@ TASK_LIST_START TEST_ENTRY (tcp_ref2) TEST_ENTRY (tcp_ref3) TEST_HELPER (tcp_ref3, tcp4_echo_server) + TEST_ENTRY (tcp_ref4) + TEST_HELPER (tcp_ref4, tcp4_echo_server) + TEST_ENTRY (tcp_ref5) + TEST_HELPER (tcp_ref5, tcp4_echo_server) TEST_ENTRY (udp_ref) TEST_ENTRY (udp_ref2) TEST_ENTRY (udp_ref3) @@ -236,6 +244,10 @@ TASK_LIST_START TEST_ENTRY (pipe_ref2) TEST_ENTRY (pipe_ref3) TEST_HELPER (pipe_ref3, pipe_echo_server) + TEST_ENTRY (pipe_ref4) + TEST_HELPER (pipe_ref4, pipe_echo_server) + TEST_ENTRY (pipe_ref5) + TEST_HELPER (pipe_ref5, pipe_echo_server) TEST_ENTRY (process_ref) TEST_ENTRY (loop_handles) diff --git a/test/test-ref.c b/test/test-ref.c index 2b8aabbc..9a474b56 100644 --- a/test/test-ref.c +++ b/test/test-ref.c @@ -26,11 +26,39 @@ #include +static uv_write_t write_req; +static uv_shutdown_t shutdown_req; +static uv_connect_t connect_req; + +static char buffer[32767]; + + static void fail_cb(void) { FATAL("fail_cb should not have been called"); } +static void write_unref_cb(uv_connect_t* req, int status) { + uv_buf_t buf = uv_buf_init(buffer, sizeof buffer); + + ASSERT(req == &connect_req); + ASSERT(status == 0); + + uv_write(&write_req, req->handle, &buf, 1, (uv_write_cb) fail_cb); + uv_unref(uv_default_loop()); // uv_write refs the loop +} + + + +static void shutdown_unref_cb(uv_connect_t* req, int status) { + ASSERT(req == &connect_req); + ASSERT(status == 0); + + uv_shutdown(&shutdown_req, req->handle, (uv_shutdown_cb) fail_cb); + uv_unref(uv_default_loop()); // uv_shutdown refs the loop +} + + TEST_IMPL(ref) { uv_run(uv_default_loop()); return 0; @@ -142,10 +170,9 @@ TEST_IMPL(tcp_ref2) { TEST_IMPL(tcp_ref3) { struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT); - uv_connect_t req; uv_tcp_t h; uv_tcp_init(uv_default_loop(), &h); - uv_tcp_connect(&req, &h, addr, (uv_connect_cb)fail_cb); + uv_tcp_connect(&connect_req, &h, addr, (uv_connect_cb)fail_cb); uv_unref(uv_default_loop()); uv_unref(uv_default_loop()); /* connect req refs the loop */ uv_run(uv_default_loop()); @@ -153,6 +180,28 @@ TEST_IMPL(tcp_ref3) { } +TEST_IMPL(tcp_ref4) { + struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT); + uv_tcp_t h; + uv_tcp_init(uv_default_loop(), &h); + uv_tcp_connect(&connect_req, &h, addr, write_unref_cb); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); + return 0; +} + + +TEST_IMPL(tcp_ref5) { + struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT); + uv_tcp_t h; + uv_tcp_init(uv_default_loop(), &h); + uv_tcp_connect(&connect_req, &h, addr, shutdown_unref_cb); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); + return 0; +} + + TEST_IMPL(udp_ref) { uv_udp_t h; uv_udp_init(uv_default_loop(), &h); @@ -210,10 +259,9 @@ TEST_IMPL(pipe_ref2) { TEST_IMPL(pipe_ref3) { - uv_connect_t req; uv_pipe_t h; uv_pipe_init(uv_default_loop(), &h, 0); - uv_pipe_connect(&req, &h, TEST_PIPENAME, (uv_connect_cb)fail_cb); + uv_pipe_connect(&connect_req, &h, TEST_PIPENAME, (uv_connect_cb)fail_cb); uv_unref(uv_default_loop()); uv_unref(uv_default_loop()); /* connect req refs the loop */ uv_run(uv_default_loop()); @@ -221,6 +269,26 @@ TEST_IMPL(pipe_ref3) { } +TEST_IMPL(pipe_ref4) { + uv_pipe_t h; + uv_pipe_init(uv_default_loop(), &h, 0); + uv_pipe_connect(&connect_req, &h, TEST_PIPENAME, write_unref_cb); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); + return 0; +} + + +TEST_IMPL(pipe_ref5) { + uv_pipe_t h; + uv_pipe_init(uv_default_loop(), &h, 0); + uv_pipe_connect(&connect_req, &h, TEST_PIPENAME, shutdown_unref_cb); + uv_unref(uv_default_loop()); + uv_run(uv_default_loop()); + return 0; +} + + TEST_IMPL(process_ref) { /* spawn_helper4 blocks indefinitely. */ char *argv[] = { NULL, "spawn_helper4", NULL };