This repository has been archived by the owner on May 4, 2018. It is now read-only.
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
test: add lots of refcount tests
- Loading branch information
1 parent
dc3b80a
commit ac218a7
Showing
5 changed files
with
199 additions
and
120 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,14 @@ | |
#include "uv.h" | ||
#include "task.h" | ||
|
||
#include <stdlib.h> | ||
#include <string.h> | ||
|
||
|
||
static void fail_cb(void) { | ||
FATAL("fail_cb should not have been called"); | ||
} | ||
|
||
|
||
TEST_IMPL(ref) { | ||
uv_run(uv_default_loop()); | ||
|
@@ -83,3 +91,164 @@ TEST_IMPL(unref_in_prepare_cb) { | |
uv_run(uv_default_loop()); | ||
return 0; | ||
} | ||
|
||
|
||
TEST_IMPL(timer_ref) { | ||
uv_timer_t h; | ||
uv_timer_init(uv_default_loop(), &h); | ||
uv_unref(uv_default_loop()); | ||
uv_run(uv_default_loop()); | ||
return 0; | ||
} | ||
|
||
|
||
TEST_IMPL(timer_ref2) { | ||
uv_timer_t h; | ||
uv_timer_init(uv_default_loop(), &h); | ||
uv_timer_start(&h, (uv_timer_cb) fail_cb, 42, 42); | ||
uv_unref(uv_default_loop()); | ||
uv_run(uv_default_loop()); | ||
return 0; | ||
} | ||
|
||
|
||
TEST_IMPL(fs_event_ref) { | ||
uv_fs_event_t h; | ||
uv_fs_event_init(uv_default_loop(), &h, ".", (uv_fs_event_cb) fail_cb, 0); | ||
uv_unref(uv_default_loop()); | ||
uv_run(uv_default_loop()); | ||
return 0; | ||
} | ||
|
||
|
||
TEST_IMPL(tcp_ref) { | ||
uv_tcp_t h; | ||
uv_tcp_init(uv_default_loop(), &h); | ||
uv_unref(uv_default_loop()); | ||
uv_run(uv_default_loop()); | ||
return 0; | ||
} | ||
|
||
|
||
TEST_IMPL(tcp_ref2) { | ||
uv_tcp_t h; | ||
uv_tcp_init(uv_default_loop(), &h); | ||
uv_listen((uv_stream_t*)&h, 128, (uv_connection_cb)fail_cb); | ||
uv_unref(uv_default_loop()); | ||
uv_run(uv_default_loop()); | ||
return 0; | ||
} | ||
|
||
|
||
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_unref(uv_default_loop()); | ||
uv_unref(uv_default_loop()); /* connect req refs the loop */ | ||
uv_run(uv_default_loop()); | ||
return 0; | ||
} | ||
|
||
|
||
TEST_IMPL(udp_ref) { | ||
uv_udp_t h; | ||
uv_udp_init(uv_default_loop(), &h); | ||
uv_unref(uv_default_loop()); | ||
uv_run(uv_default_loop()); | ||
return 0; | ||
} | ||
|
||
|
||
TEST_IMPL(udp_ref2) { | ||
struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT); | ||
uv_udp_t h; | ||
uv_udp_init(uv_default_loop(), &h); | ||
uv_udp_bind(&h, addr, 0); | ||
uv_udp_recv_start(&h, (uv_alloc_cb)fail_cb, (uv_udp_recv_cb)fail_cb); | ||
uv_unref(uv_default_loop()); | ||
uv_run(uv_default_loop()); | ||
return 0; | ||
} | ||
|
||
|
||
TEST_IMPL(udp_ref3) { | ||
struct sockaddr_in addr = uv_ip4_addr("127.0.0.1", TEST_PORT); | ||
uv_buf_t buf = uv_buf_init("PING", 4); | ||
uv_udp_send_t req; | ||
uv_udp_t h; | ||
|
||
uv_udp_init(uv_default_loop(), &h); | ||
uv_udp_send(&req, &h, &buf, 1, addr, (uv_udp_send_cb)fail_cb); | ||
uv_unref(uv_default_loop()); | ||
uv_unref(uv_default_loop()); /* send req refs the loop */ | ||
This comment has been minimized.
Sorry, something went wrong. |
||
uv_run(uv_default_loop()); | ||
|
||
return 0; | ||
} | ||
|
||
|
||
TEST_IMPL(pipe_ref) { | ||
uv_pipe_t h; | ||
uv_pipe_init(uv_default_loop(), &h, 0); | ||
uv_unref(uv_default_loop()); | ||
uv_run(uv_default_loop()); | ||
return 0; | ||
} | ||
|
||
|
||
TEST_IMPL(pipe_ref2) { | ||
uv_pipe_t h; | ||
uv_pipe_init(uv_default_loop(), &h, 0); | ||
uv_listen((uv_stream_t*)&h, 128, (uv_connection_cb)fail_cb); | ||
uv_unref(uv_default_loop()); | ||
uv_run(uv_default_loop()); | ||
return 0; | ||
} | ||
|
||
|
||
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_unref(uv_default_loop()); | ||
uv_unref(uv_default_loop()); /* connect req refs the loop */ | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
bnoordhuis
Author
Contributor
|
||
uv_run(uv_default_loop()); | ||
return 0; | ||
} | ||
|
||
|
||
TEST_IMPL(process_ref) { | ||
/* spawn_helper4 blocks indefinitely. */ | ||
char *argv[] = { NULL, "spawn_helper4", NULL }; | ||
uv_process_options_t options; | ||
size_t exepath_size; | ||
char exepath[256]; | ||
uv_process_t h; | ||
int r; | ||
|
||
memset(&options, 0, sizeof(options)); | ||
exepath_size = sizeof(exepath); | ||
|
||
r = uv_exepath(exepath, &exepath_size); | ||
ASSERT(r == 0); | ||
|
||
argv[0] = exepath; | ||
options.file = exepath; | ||
options.args = argv; | ||
options.exit_cb = NULL; | ||
|
||
r = uv_spawn(uv_default_loop(), &h, options); | ||
ASSERT(r == 0); | ||
|
||
uv_unref(uv_default_loop()); | ||
uv_run(uv_default_loop()); | ||
|
||
r = uv_process_kill(&h, /* SIGTERM */ 15); | ||
ASSERT(r == 0); | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
I am not against it - but I dont think we ever decided that requests ref the loop. Only "standalone" requests that do not operate on a handle ref the event loop at the moment.