This test checks that we can reap a non-child process, in terms of receiving the termination notification.
| 44 | // This test checks that we can reap a non-child process, in terms |
| 45 | // of receiving the termination notification. |
| 46 | TEST(ReapTest, NonChildProcess) |
| 47 | { |
| 48 | // The child process creates a grandchild and then exits. The |
| 49 | // grandchild sleeps for 10 seconds. The process tree looks like: |
| 50 | // -+- child exit 0 |
| 51 | // \-+- grandchild sleep 10 |
| 52 | |
| 53 | // After the child exits, the grandchild is going to be re-parented |
| 54 | // by 'init', like this: |
| 55 | // -+- child (exit 0) |
| 56 | // -+- grandchild sleep 10 |
| 57 | Try<ProcessTree> tree = Fork(None(), |
| 58 | Fork(Exec(SLEEP_COMMAND(10))), |
| 59 | Exec("exit 0"))(); |
| 60 | ASSERT_SOME(tree); |
| 61 | ASSERT_EQ(1u, tree->children.size()); |
| 62 | pid_t grandchild = tree->children.front(); |
| 63 | |
| 64 | // Reap the grandchild process. |
| 65 | Future<Option<int>> status = process::reap(grandchild); |
| 66 | |
| 67 | EXPECT_TRUE(status.isPending()); |
| 68 | |
| 69 | // Now kill the grandchild. |
| 70 | // NOTE: We send a SIGKILL here because sometimes the grandchild |
| 71 | // process seems to be in a hung state and not responding to |
| 72 | // SIGTERM/SIGINT. |
| 73 | EXPECT_EQ(0, kill(grandchild, SIGKILL)); |
| 74 | |
| 75 | Clock::pause(); |
| 76 | |
| 77 | // Now advance time until the Reaper reaps the grandchild. |
| 78 | while (status.isPending()) { |
| 79 | Clock::advance(MAX_REAP_INTERVAL()); |
| 80 | Clock::settle(); |
| 81 | } |
| 82 | |
| 83 | AWAIT_READY(status); |
| 84 | |
| 85 | // The status is None because pid is not an immediate child. |
| 86 | ASSERT_NONE(status.get()) << status->get(); |
| 87 | |
| 88 | // Reap the child as well to clean up after ourselves. |
| 89 | status = process::reap(tree->process.pid); |
| 90 | |
| 91 | // Now advance time until the child is reaped. |
| 92 | while (status.isPending()) { |
| 93 | Clock::advance(MAX_REAP_INTERVAL()); |
| 94 | Clock::settle(); |
| 95 | } |
| 96 | |
| 97 | // Check if the status is correct. |
| 98 | AWAIT_EXPECT_WEXITSTATUS_EQ(0, status); |
| 99 | |
| 100 | Clock::resume(); |
| 101 | } |
| 102 | |
| 103 |
nothing calls this directly
no test coverage detected