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

Commit

Permalink
Add tcp reference count tests
Browse files Browse the repository at this point in the history
  • Loading branch information
ry committed Sep 27, 2011
1 parent 3e5aa06 commit 2ebb227
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 0 deletions.
8 changes: 8 additions & 0 deletions test/test-list.h
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -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)

Expand Down
47 changes: 47 additions & 0 deletions test/test-tcp-close.c
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

1 comment on commit 2ebb227

@ry
Copy link
Contributor Author

@ry ry commented on 2ebb227 Sep 27, 2011

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

uv_tcp_ref2 exposes a bug / discrepancy between the windows and unix backends. Windows only makes one reference count for a connecting socket - Unix does too. Related to nodejs/node-v0.x-archive#1726.

Please sign in to comment.