You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by be...@apache.org on 2013/05/26 18:57:50 UTC

[25/28] git commit: Updated MonitorTest.WatchUnwatch to be deterministic.

Updated MonitorTest.WatchUnwatch to be deterministic.

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


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

Branch: refs/heads/master
Commit: 4392c6e3b7b3dfabfc11a73f930063ad9fe92bc8
Parents: bc9cb87
Author: Benjamin Hindman <be...@twitter.com>
Authored: Thu May 23 13:44:30 2013 -0700
Committer: Benjamin Hindman <be...@twitter.com>
Committed: Sun May 26 09:28:38 2013 -0700

----------------------------------------------------------------------
 src/tests/monitor_tests.cpp |   34 ++++++++++++++++++++++++----------
 1 files changed, 24 insertions(+), 10 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-mesos/blob/4392c6e3/src/tests/monitor_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/monitor_tests.cpp b/src/tests/monitor_tests.cpp
index 5681af2..53920a0 100644
--- a/src/tests/monitor_tests.cpp
+++ b/src/tests/monitor_tests.cpp
@@ -29,6 +29,8 @@
 #include <process/pid.hpp>
 #include <process/process.hpp>
 
+#include <stout/nothing.hpp>
+
 #include "slave/constants.hpp"
 #include "slave/monitor.hpp"
 
@@ -49,6 +51,7 @@ using process::http::Response;
 using std::string;
 
 using testing::_;
+using testing::DoAll;
 using testing::Return;
 
 
@@ -79,14 +82,17 @@ TEST(MonitorTest, WatchUnwatch)
 
   process::spawn(isolator);
 
+  Future<Nothing> usage;
   EXPECT_CALL(isolator, usage(frameworkId, executorId))
-    .WillRepeatedly(Return(statistics));
+    .WillOnce(DoAll(FutureSatisfy(&usage),
+                    Return(statistics)));
 
   slave::ResourceMonitor monitor(&isolator);
 
-  // Monitor the executor.
-  Future<Nothing> watch =
-    FUTURE_DISPATCH(_, &slave::ResourceMonitorProcess::watch);
+  // We pause the clock first in order to make sure that we can
+  // advance time below to force the 'delay' in
+  // ResourceMonitorProcess::watch to execute.
+  process::Clock::pause();
 
   monitor.watch(
       frameworkId,
@@ -94,12 +100,18 @@ TEST(MonitorTest, WatchUnwatch)
       executorInfo,
       slave::RESOURCE_MONITORING_INTERVAL);
 
-  AWAIT_READY(watch);
+  // Now wait for ResouorceMonitorProcess::watch to finish so we can
+  // advance time to cause collection to begin.
+  process::Clock::settle();
 
-  process::Clock::pause();
   process::Clock::advance(slave::RESOURCE_MONITORING_INTERVAL);
   process::Clock::settle();
 
+  AWAIT_READY(usage);
+
+  // Wait until the isolator has finished returning the statistics.
+  process::Clock::settle();
+
   process::UPID upid("monitor", process::ip(), process::port());
 
   Future<Response> response = process::http::get(upid, "usage.json");
@@ -130,12 +142,14 @@ TEST(MonitorTest, WatchUnwatch)
       response);
 
   // Ensure the monitor stops polling the isolator.
-  Future<Nothing> unwatch =
-    FUTURE_DISPATCH(_, &slave::ResourceMonitorProcess::unwatch);
-
   monitor.unwatch(frameworkId, executorId);
 
-  AWAIT_READY(unwatch);
+  // Wait until ResourceMonitorProcess::unwatch has completed.
+  process::Clock::settle();
+
+  // This time, Isolator::usage should not get called.
+  EXPECT_CALL(isolator, usage(frameworkId, executorId))
+    .Times(0);
 
   process::Clock::advance(slave::RESOURCE_MONITORING_INTERVAL);
   process::Clock::settle();