summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChase Douglas <chase.douglas@canonical.com>2012-04-20 09:41:45 -0700
committerChase Douglas <chase.douglas@canonical.com>2012-04-20 09:41:45 -0700
commit243107ee0f55614df4722c629538e5250795485c (patch)
tree2357b5179516067ce339cbad46b69eff614e9148
parent15bcb46183f73025485a63d10947403da1ff412e (diff)
Wait for dummy X server to shut down in Environment::TearDown()fixes
If two xorg-gtest binaries are executed one after another, the second one may attempt to start its X server before the first one's X server has fully shut down. This leads to the second X server not starting. Signed-off-by: Chase Douglas <chase.douglas@canonical.com>
-rw-r--r--src/environment.cpp30
1 files changed, 24 insertions, 6 deletions
diff --git a/src/environment.cpp b/src/environment.cpp
index c1c4d80..d7d1c82 100644
--- a/src/environment.cpp
+++ b/src/environment.cpp
@@ -144,17 +144,35 @@ void xorg::testing::Environment::SetUp() {
}
void xorg::testing::Environment::TearDown() {
- if (!d_->process.Terminate()) {
- std::cerr << "Warning: Failed to terminate dummy Xorg server: "
- << std::strerror(errno) << "\n";
- if (!d_->process.Kill())
- std::cerr << "Warning: Failed to kill dummy Xorg server: "
- << std::strerror(errno) << "\n";
+ if (d_->process.Terminate()) {
+ for (int i = 0; i < 10; i++) {
+ int status;
+ int pid = waitpid(d_->process.Pid(), &status, WNOHANG);
+
+ if (pid == d_->process.Pid())
+ return;
+
+ sleep(1); /* Give the dummy X server more time to shut down */
+ }
}
+
+ Kill();
}
void xorg::testing::Environment::Kill() {
if (!d_->process.Kill())
std::cerr << "Warning: Failed to kill dummy Xorg server: "
<< std::strerror(errno) << "\n";
+
+ for (int i = 0; i < 10; i++) {
+ int status;
+ int pid = waitpid(d_->process.Pid(), &status, WNOHANG);
+
+ if (pid == d_->process.Pid())
+ return;
+
+ sleep(1); /* Give the dummy X server more time to shut down */
+ }
+
+ std::cerr << "Warning: Dummy X server did not shut down\n";
}