MCPcopy Create free account
hub / github.com/apache/mesos / TEST

Function TEST

3rdparty/libprocess/src/tests/reap_tests.cpp:46–101  ·  view source on GitHub ↗

This test checks that we can reap a non-child process, in terms of receiving the termination notification.

Source from the content-addressed store, hash-verified

44// This test checks that we can reap a non-child process, in terms
45// of receiving the termination notification.
46TEST(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

Callers

nothing calls this directly

Calls 12

NoneClass · 0.85
reapFunction · 0.85
MAX_REAP_INTERVALFunction · 0.85
MillisecondsClass · 0.85
ForkClass · 0.50
ExecClass · 0.50
killFunction · 0.50
processFunction · 0.50
sleepFunction · 0.50
sizeMethod · 0.45
isPendingMethod · 0.45
getMethod · 0.45

Tested by

no test coverage detected