test: Add test case for spawning detached child processes.

This commit is contained in:
Charlie McConnell 2012-02-23 23:16:59 -08:00 committed by Ben Noordhuis
parent e99fdf0df6
commit ea9baef95c
2 changed files with 36 additions and 0 deletions

View File

@ -104,6 +104,7 @@ TEST_DECLARE (spawn_exit_code)
TEST_DECLARE (spawn_stdout)
TEST_DECLARE (spawn_stdin)
TEST_DECLARE (spawn_and_kill)
TEST_DECLARE (spawn_detached)
TEST_DECLARE (spawn_and_kill_with_std)
TEST_DECLARE (spawn_and_ping)
TEST_DECLARE (kill)
@ -279,6 +280,7 @@ TASK_LIST_START
TEST_ENTRY (spawn_stdout)
TEST_ENTRY (spawn_stdin)
TEST_ENTRY (spawn_and_kill)
TEST_ENTRY (spawn_detached)
TEST_ENTRY (spawn_and_kill_with_std)
TEST_ENTRY (spawn_and_ping)
TEST_ENTRY (kill)

View File

@ -77,6 +77,22 @@ static void kill_cb(uv_process_t* process, int exit_status, int term_signal) {
ASSERT(err.code == UV_ESRCH);
}
static void detach_cb(uv_process_t* process, int exit_status, int term_signal) {
uv_err_t err;
printf("detach_cb\n");
exit_cb_called++;
ASSERT(exit_status == 0);
uv_close((uv_handle_t*)process, close_cb);
/*
* Unlike other tests, this one needs to make sure the process *is*
* still alive.
*/
err = uv_kill(process->pid, 0);
ASSERT(err.code == 0);
err = uv_kill(process->pid, 15);
ASSERT(err.code == 0);
}
static uv_buf_t on_alloc(uv_handle_t* handle, size_t suggested_size) {
uv_buf_t buf;
@ -230,6 +246,24 @@ TEST_IMPL(spawn_and_kill) {
return 0;
}
TEST_IMPL(spawn_detached) {
int r;
init_process_options("spawn_helper4", detach_cb);
options.detached = 1;
r = uv_spawn(uv_default_loop(), &process, options);
ASSERT(r == 0);
r = uv_run(uv_default_loop());
ASSERT(r == 0);
ASSERT(exit_cb_called == 1);
ASSERT(close_cb_called == 1);
return 0;
}
TEST_IMPL(spawn_and_kill_with_std) {
int r;