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

Commit

Permalink
test: Add test case for spawning detached child processes.
Browse files Browse the repository at this point in the history
  • Loading branch information
AvianFlu authored and bnoordhuis committed Feb 24, 2012
1 parent e99fdf0 commit ea9baef
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 0 deletions.
2 changes: 2 additions & 0 deletions test/test-list.h
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down
34 changes: 34 additions & 0 deletions test/test-spawn.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down

0 comments on commit ea9baef

Please sign in to comment.