Repository: mesos
Updated Branches:
  refs/heads/master 5f40f3d40 -> ee621bb36


Fixed flaky `NestedMesosContainerizerTest` tests.

This patch is an addition to commit 0cc636b2d5.

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


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

Branch: refs/heads/master
Commit: 196fe20861a4efc8edcabb08ce8821e8ed1b8f02
Parents: 5f40f3d
Author: Andrei Budnik <abud...@mesosphere.com>
Authored: Wed Dec 20 14:59:50 2017 +0100
Committer: Alexander Rukletsov <al...@apache.org>
Committed: Wed Dec 20 14:59:50 2017 +0100

----------------------------------------------------------------------
 .../nested_mesos_containerizer_tests.cpp        | 67 ++++++++++----------
 1 file changed, 35 insertions(+), 32 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/196fe208/src/tests/containerizer/nested_mesos_containerizer_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/nested_mesos_containerizer_tests.cpp 
b/src/tests/containerizer/nested_mesos_containerizer_tests.cpp
index 92832e7..db60bfb 100644
--- a/src/tests/containerizer/nested_mesos_containerizer_tests.cpp
+++ b/src/tests/containerizer/nested_mesos_containerizer_tests.cpp
@@ -2064,40 +2064,43 @@ TEST_F(NestedMesosContainerizerTest,
   ContainerID containerId;
   containerId.set_value(id::UUID::random().toString());
 
-  string cgroup = path::join(
+  string cgroupParent = path::join(
       flags.cgroups_root,
       buildPath(containerId, "mesos", JOIN));
 
-  ASSERT_SOME(cgroups::create(freezerHierarchy.get(), cgroup, true));
+  ASSERT_SOME(cgroups::create(freezerHierarchy.get(), cgroupParent, true));
+  ASSERT_SOME_TRUE(cgroups::exists(freezerHierarchy.get(), cgroupParent));
 
   ContainerID nestedContainerId;
   nestedContainerId.mutable_parent()->CopyFrom(containerId);
   nestedContainerId.set_value(id::UUID::random().toString());
 
-  cgroup = path::join(
+  string cgroupNested = path::join(
       flags.cgroups_root,
       buildPath(nestedContainerId, "mesos", JOIN));
 
-  ASSERT_SOME(cgroups::create(freezerHierarchy.get(), cgroup, true));
+  ASSERT_SOME(cgroups::create(freezerHierarchy.get(), cgroupNested, true));
+  ASSERT_SOME_TRUE(cgroups::exists(freezerHierarchy.get(), cgroupNested));
 
   SlaveState state;
   state.id = SlaveID();
 
   AWAIT_READY(containerizer->recover(state));
 
-  Future<Option<ContainerTermination>> wait = containerizer->wait(
-      nestedContainerId);
-
-  AWAIT_READY(wait);
-  ASSERT_SOME(wait.get());
+  // We expect that containerizer recovery will detect orphan containers and
+  // will destroy them, so we check here that the freezer cgroups are 
destroyed.
+  //
+  // NOTE: `wait()` can return `Some` or `None` due to a race condition between
+  // `recover()` and `______destroy()` for an orphan container.
+  AWAIT_READY(containerizer->wait(nestedContainerId));
+  ASSERT_SOME_FALSE(cgroups::exists(freezerHierarchy.get(), cgroupNested));
 
   Future<hashset<ContainerID>> containers = containerizer->containers();
   AWAIT_READY(containers);
   ASSERT_FALSE(containers->contains(nestedContainerId));
 
-  wait = containerizer->wait(containerId);
-  AWAIT_READY(wait);
-  ASSERT_SOME(wait.get());
+  AWAIT_READY(containerizer->wait(containerId));
+  ASSERT_SOME_FALSE(cgroups::exists(freezerHierarchy.get(), cgroupParent));
 
   containers = containerizer->containers();
   AWAIT_READY(containers);
@@ -2436,53 +2439,53 @@ TEST_F(NestedMesosContainerizerTest,
   ContainerID containerId;
   containerId.set_value(id::UUID::random().toString());
 
-  string cgroup = path::join(
+  string cgroupParent = path::join(
       flags.cgroups_root,
       buildPath(containerId, "mesos", JOIN));
 
-  ASSERT_SOME(cgroups::create(freezerHierarchy.get(), cgroup, true));
+  ASSERT_SOME(cgroups::create(freezerHierarchy.get(), cgroupParent, true));
+  ASSERT_SOME_TRUE(cgroups::exists(freezerHierarchy.get(), cgroupParent));
 
   ContainerID nestedContainerId1;
   nestedContainerId1.mutable_parent()->CopyFrom(containerId);
   nestedContainerId1.set_value(id::UUID::random().toString());
 
-  cgroup = path::join(
+  string cgroupNested1 = path::join(
       flags.cgroups_root,
       buildPath(nestedContainerId1, "mesos", JOIN));
 
-  ASSERT_SOME(cgroups::create(freezerHierarchy.get(), cgroup, true));
+  ASSERT_SOME(cgroups::create(freezerHierarchy.get(), cgroupNested1, true));
+  ASSERT_SOME_TRUE(cgroups::exists(freezerHierarchy.get(), cgroupNested1));
 
   ContainerID nestedContainerId2;
   nestedContainerId2.mutable_parent()->CopyFrom(containerId);
   nestedContainerId2.set_value(id::UUID::random().toString());
 
-  cgroup = path::join(
+  string cgroupNested2 = path::join(
       flags.cgroups_root,
       buildPath(nestedContainerId2, "mesos", JOIN));
 
-  ASSERT_SOME(cgroups::create(freezerHierarchy.get(), cgroup, true));
+  ASSERT_SOME(cgroups::create(freezerHierarchy.get(), cgroupNested2, true));
+  ASSERT_SOME_TRUE(cgroups::exists(freezerHierarchy.get(), cgroupNested2));
 
   SlaveState state;
   state.id = SlaveID();
 
   AWAIT_READY(containerizer->recover(state));
 
-  Future<Option<ContainerTermination>> nestedWait1 = containerizer->wait(
-      nestedContainerId1);
-
-  Future<Option<ContainerTermination>> nestedWait2 = containerizer->wait(
-      nestedContainerId2);
-
-  Future<Option<ContainerTermination>> wait = containerizer->wait(containerId);
-
-  AWAIT_READY(nestedWait1);
-  ASSERT_SOME(nestedWait1.get());
+  // We expect that containerizer recovery will detect orphan containers and
+  // will destroy them, so we check here that the freezer cgroups are 
destroyed.
+  //
+  // NOTE: `wait()` can return `Some` or `None` due to a race condition between
+  // `recover()` and `______destroy()` for an orphan container.
+  AWAIT_READY(containerizer->wait(nestedContainerId1));
+  ASSERT_SOME_FALSE(cgroups::exists(freezerHierarchy.get(), cgroupNested1));
 
-  AWAIT_READY(nestedWait2);
-  ASSERT_SOME(nestedWait2.get());
+  AWAIT_READY(containerizer->wait(nestedContainerId2));
+  ASSERT_SOME_FALSE(cgroups::exists(freezerHierarchy.get(), cgroupNested2));
 
-  AWAIT_READY(wait);
-  ASSERT_SOME(wait.get());
+  AWAIT_READY(containerizer->wait(containerId));
+  ASSERT_SOME_FALSE(cgroups::exists(freezerHierarchy.get(), cgroupParent));
 
   Future<hashset<ContainerID>> containers = containerizer->containers();
   AWAIT_READY(containers);

Reply via email to