Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

test: Test case for spawning a detached child process.

  • Loading branch information...
commit 0e6c2d8ca95fb97eaef03e05ce796ea1c8d851e8 1 parent 10614a9
@AvianFlu authored
Showing with 36 additions and 0 deletions.
  1. +2 −0  test/test-list.h
  2. +34 −0 test/test-spawn.c
View
2  test/test-list.h
@@ -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
34 test/test-spawn.c
@@ -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;
Please sign in to comment.
Something went wrong with that request. Please try again.