Repository: mesos
Updated Branches:
  refs/heads/master 991ff131c -> 180129dbd


Fixed a race in the test `ROOT_MultiTaskgroupSharePidNamespace`.

In the test `DefaultExecutorTest.ROOT_MultiTaskgroupSharePidNamespace`,
we read the file `ns` in each of the two task's sandbox and check if
their contents (the pid namespace of the task itself) are same. However
it is possible we do the read for the second task after that file is
created but before it is written, i.e., the content we read from the
`ns` file of the second task would be empty which will cause the check
failed.

In this patch, we read the file `ns` for each task in a while loop, and
only break from the loop when both task's files are not empty.

Review: https://reviews.apache.org/r/65278


Project: http://git-wip-us.apache.org/repos/asf/mesos/repo
Commit: http://git-wip-us.apache.org/repos/asf/mesos/commit/180129db
Tree: http://git-wip-us.apache.org/repos/asf/mesos/tree/180129db
Diff: http://git-wip-us.apache.org/repos/asf/mesos/diff/180129db

Branch: refs/heads/master
Commit: 180129dbd2cc2d8e130e860a4de30d211a69f6be
Parents: 991ff13
Author: Qian Zhang <zhq527...@gmail.com>
Authored: Tue Jan 23 08:33:03 2018 +0800
Committer: Qian Zhang <zhq527...@gmail.com>
Committed: Wed Jan 24 14:22:44 2018 +0800

----------------------------------------------------------------------
 src/tests/default_executor_tests.cpp | 27 ++++++++++++++++++++-------
 1 file changed, 20 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/180129db/src/tests/default_executor_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/default_executor_tests.cpp 
b/src/tests/default_executor_tests.cpp
index 065eae6..f8ae037 100644
--- a/src/tests/default_executor_tests.cpp
+++ b/src/tests/default_executor_tests.cpp
@@ -1837,23 +1837,36 @@ TEST_P(DefaultExecutorTest, 
ROOT_MultiTaskgroupSharePidNamespace)
 
   // Wait up to 10 seconds for each of the two tasks to
   // write its pid namespace inode into its sandbox.
+  Option<string> pidNamespace1;
+  Option<string> pidNamespace2;
+
   Duration waited = Duration::zero();
   do {
     if (os::exists(pidNamespacePath1) && os::exists(pidNamespacePath2)) {
-      break;
+      Try<string> pidNamespace = os::read(pidNamespacePath1);
+      ASSERT_SOME(pidNamespace);
+
+      pidNamespace1 = pidNamespace.get();
+
+      pidNamespace = os::read(pidNamespacePath2);
+      ASSERT_SOME(pidNamespace);
+
+      pidNamespace2 = pidNamespace.get();
+
+      // It is possible that the `ns` file has been created but not written
+      // yet (i.e., an empty file). To avoid comparing empty file, we will
+      // only break from this loop when both task's `ns` files are not empty.
+      if (!(strings::trim(pidNamespace1.get()).empty()) &&
+          !(strings::trim(pidNamespace2.get()).empty())) {
+        break;
+      }
     }
 
     os::sleep(Seconds(1));
     waited += Seconds(1);
   } while (waited < Seconds(10));
 
-  EXPECT_TRUE(os::exists(pidNamespacePath1));
-  EXPECT_TRUE(os::exists(pidNamespacePath2));
-
-  Try<string> pidNamespace1 = os::read(pidNamespacePath1);
   ASSERT_SOME(pidNamespace1);
-
-  Try<string> pidNamespace2 = os::read(pidNamespacePath2);
   ASSERT_SOME(pidNamespace2);
 
   // Check the two tasks share the same pid namespace.

Reply via email to