update_engine: clean up sleep process in P2PManagerTest.LookupURL
P2PManagerTest.LookupURL terminates a 'sh' process, which is put into
sleep by executing `sleep 2`. Upon receiving SIGTERM, the 'sleep'
process isn't reaped and thus becomes orphaned. As a remedy, this CL
modifies the shell command to trap SIGTERM and kill the 'sleep' process
upon receiving SIGTERM.
BUG=chromium:678643
TEST=Verified that no orphaned 'sleep' process is left after running
P2PManagerTest.LookupURL.
Change-Id: I05aaf14ee39ff77a7a2040f97a19bcc9d70046a8
Reviewed-on: https://chromium-review.googlesource.com/427060
Commit-Ready: Ben Chan <benchan@chromium.org>
Tested-by: Ben Chan <benchan@chromium.org>
Reviewed-by: Mike Frysinger <vapier@chromium.org>
diff --git a/p2p_manager_unittest.cc b/p2p_manager_unittest.cc
index 463c0e2..5ffb358 100644
--- a/p2p_manager_unittest.cc
+++ b/p2p_manager_unittest.cc
@@ -506,7 +506,18 @@
// Emulate p2p-client exceeding its timeout.
test_conf_->SetP2PClientCommand({
- "sh", "-c", "echo http://1.2.3.4/; sleep 2"});
+ "sh", "-c",
+ // The 'sleep' launched below could be left behind as an orphaned
+ // process when the 'sh' process is terminated by SIGTERM. As a
+ // remedy, trap SIGTERM and kill the 'sleep' process, which requires
+ // launching 'sleep' in background and then waiting for it.
+ "cleanup() { kill \"${sleep_pid}\"; exit 0; }; "
+ "trap cleanup TERM; "
+ "sleep 5 & "
+ "sleep_pid=$!; "
+ "echo http://1.2.3.4/; "
+ "wait"
+ });
manager_->LookupUrlForFile("foobar", 42, TimeDelta::FromMilliseconds(500),
base::Bind(ExpectUrl, ""));
loop_.Run();