Windows: Ported `Cpu` and `Mem` isolator tests.

These test the limitation and usage reporting of the new Windows `Cpu`
and `Mem` isolators.

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


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

Branch: refs/heads/master
Commit: b4cf87ba7cf32aee7e71ec2ca921006c914517f2
Parents: 80ed0ed
Author: Andrew Schwartzmeyer <[email protected]>
Authored: Fri Oct 20 12:46:21 2017 -0700
Committer: Andrew Schwartzmeyer <[email protected]>
Committed: Thu Nov 30 15:54:53 2017 -0800

----------------------------------------------------------------------
 src/tests/CMakeLists.txt                        |  4 +--
 src/tests/containerizer/cpu_isolator_tests.cpp  | 35 +++++++++++++++-----
 .../containerizer/memory_isolator_tests.cpp     | 15 ++++++++-
 src/tests/mesos.cpp                             |  2 +-
 4 files changed, 44 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/b4cf87ba/src/tests/CMakeLists.txt
----------------------------------------------------------------------
diff --git a/src/tests/CMakeLists.txt b/src/tests/CMakeLists.txt
index 65fca82..5e52020 100644
--- a/src/tests/CMakeLists.txt
+++ b/src/tests/CMakeLists.txt
@@ -145,6 +145,8 @@ list(APPEND MESOS_TESTS_SRC
 
 list(APPEND MESOS_TESTS_SRC
   containerizer/containerizer_tests.cpp
+  containerizer/cpu_isolator_tests.cpp
+  containerizer/memory_isolator_tests.cpp
   containerizer/docker_tests.cpp)
 
 if (NOT WIN32)
@@ -185,13 +187,11 @@ if (NOT WIN32)
   list(APPEND MESOS_TESTS_SRC
     containerizer/appc_spec_tests.cpp
     containerizer/composing_containerizer_tests.cpp
-    containerizer/cpu_isolator_tests.cpp
     containerizer/docker_containerizer_tests.cpp
     containerizer/docker_spec_tests.cpp
     containerizer/environment_secret_isolator_tests.cpp
     containerizer/io_switchboard_tests.cpp
     containerizer/isolator_tests.cpp
-    containerizer/memory_isolator_tests.cpp
     containerizer/mesos_containerizer_paths_tests.cpp
     containerizer/mesos_containerizer_tests.cpp
     containerizer/oci_spec_tests.cpp

http://git-wip-us.apache.org/repos/asf/mesos/blob/b4cf87ba/src/tests/containerizer/cpu_isolator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/cpu_isolator_tests.cpp 
b/src/tests/containerizer/cpu_isolator_tests.cpp
index 846b2e2..9498a23 100644
--- a/src/tests/containerizer/cpu_isolator_tests.cpp
+++ b/src/tests/containerizer/cpu_isolator_tests.cpp
@@ -51,10 +51,14 @@ class CpuIsolatorTest
 
 // These tests are parameterized by the isolation flag.
 static vector<string>* isolators = new vector<string>({
+#ifndef __WINDOWS__
   "posix/cpu",
 #ifdef __linux__
   "cgroups/cpu",
 #endif // __linux__
+#else
+  "windows/cpu",
+#endif // __WINDOWS__
 });
 
 
@@ -112,7 +116,12 @@ TEST_P(CpuIsolatorTest, ROOT_UserCpuUsage)
   // second.
   TaskInfo task = createTask(
       offers.get()[0],
-      "while true ; do true ; done & sleep 60");
+#ifdef __WINDOWS__
+      "powershell -c \"while ($true) {}\""
+#else
+      "while true ; do true ; done & sleep 60"
+#endif // __WINDOWS__
+    );
 
   Future<TaskStatus> statusStarting;
   Future<TaskStatus> statusRunning;
@@ -160,7 +169,10 @@ TEST_P(CpuIsolatorTest, ROOT_UserCpuUsage)
 }
 
 
-TEST_P(CpuIsolatorTest, ROOT_SystemCpuUsage)
+// TODO(andschwa): Enable this test when a command can be found that does not
+// cause a flaky test. As it is, it is difficult to consume kernel time on
+// Windows consistently.
+TEST_P_TEMP_DISABLED_ON_WINDOWS(CpuIsolatorTest, ROOT_SystemCpuUsage)
 {
   Try<Owned<cluster::Master>> master = StartMaster();
   ASSERT_SOME(master);
@@ -204,12 +216,19 @@ TEST_P(CpuIsolatorTest, ROOT_SystemCpuUsage)
   AWAIT_READY(offers);
   ASSERT_FALSE(offers->empty());
 
-  // Generating random numbers is done by the kernel and will max out
-  // a single core and run almost exclusively in the kernel, i.e.,
-  // system time.
   TaskInfo task = createTask(
       offers.get()[0],
-      "cat /dev/urandom > /dev/null & sleep 60");
+#ifdef __WINDOWS__
+      // Enumerating processes will at least cause some kernel time.
+      "powershell -NoProfile -Command "
+      "\"while ($true) { Get-Process | Out-Null }\""
+#else
+      // Generating random numbers is done by the kernel and will max out
+      // a single core and run almost exclusively in the kernel, i.e.,
+      // system time.
+      "cat /dev/urandom > /dev/null & sleep 60"
+#endif // __WINDOWS__
+    );
 
   Future<TaskStatus> statusStarting;
   Future<TaskStatus> statusRunning;
@@ -231,8 +250,8 @@ TEST_P(CpuIsolatorTest, ROOT_SystemCpuUsage)
 
   ContainerID containerId = *(containers->begin());
 
-  // Wait up to 1 second for the child process to induce 1/8 of a
-  // second of user cpu time.
+  // Wait up to 1 seconds for the child process to induce 1/8 of a
+  // second of system cpu time.
   ResourceStatistics statistics;
   Duration waited = Duration::zero();
   do {

http://git-wip-us.apache.org/repos/asf/mesos/blob/b4cf87ba/src/tests/containerizer/memory_isolator_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/containerizer/memory_isolator_tests.cpp 
b/src/tests/containerizer/memory_isolator_tests.cpp
index b8ea5d3..cd6329f 100644
--- a/src/tests/containerizer/memory_isolator_tests.cpp
+++ b/src/tests/containerizer/memory_isolator_tests.cpp
@@ -51,10 +51,14 @@ class MemoryIsolatorTest
 
 // These tests are parameterized by the isolation flag.
 static vector<string>* isolators = new vector<string>({
+#ifndef __WINDOWS__
   "posix/mem",
 #ifdef __linux__
   "cgroups/mem",
 #endif // __linux__
+#else
+  "windows/mem",
+#endif // __WINDOWS__
 });
 
 
@@ -108,7 +112,7 @@ TEST_P(MemoryIsolatorTest, ROOT_MemUsage)
   AWAIT_READY(offers);
   ASSERT_FALSE(offers->empty());
 
-  TaskInfo task = createTask(offers.get()[0], "sleep 120");
+  TaskInfo task = createTask(offers.get()[0], SLEEP_COMMAND(120));
 
   Future<TaskStatus> statusStarting;
   Future<TaskStatus> statusRunning;
@@ -135,7 +139,16 @@ TEST_P(MemoryIsolatorTest, ROOT_MemUsage)
 
   // TODO(jieyu): Consider using a program that predictably increases
   // RSS so that we can set more meaningful expectation here.
+#ifdef __WINDOWS__
+  // NOTE: Windows reports `mem_total_bytes` instead of `mem_rss_bytes` because
+  // of the change in meaning in 0.23.0. The `mem_rss_bytes` represents only
+  // anonymous memory usage, but the "working set size" reported by Windows
+  // corresponds to the total memory of a process in RAM.
+  EXPECT_LT(0u, usage->mem_total_bytes());
+#else
+  // TODO(andschwa): Consider testing `mem_total_bytes` for other platforms.
   EXPECT_LT(0u, usage->mem_rss_bytes());
+#endif // __WINDOWS__
 
   driver.stop();
   driver.join();

http://git-wip-us.apache.org/repos/asf/mesos/blob/b4cf87ba/src/tests/mesos.cpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.cpp b/src/tests/mesos.cpp
index b76eb4d..7ed08a5 100644
--- a/src/tests/mesos.cpp
+++ b/src/tests/mesos.cpp
@@ -688,7 +688,7 @@ slave::Flags 
ContainerizerTest<slave::MesosContainerizer>::CreateSlaveFlags()
     flags.isolation = "posix/cpu,posix/mem";
   }
 #elif defined(__WINDOWS__)
-  flags.isolation = "windows/cpu";
+  flags.isolation = "windows/cpu,windows/mem";
 #else
   flags.isolation = "posix/cpu,posix/mem";
 #endif

Reply via email to