You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@mesos.apache.org by nn...@apache.org on 2015/05/28 21:51:17 UTC

mesos git commit: Added test to verify fix for MESOS-2771.

Repository: mesos
Updated Branches:
  refs/heads/master 44d6ceb2c -> 5c9529777


Added test to verify fix for MESOS-2771.

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


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

Branch: refs/heads/master
Commit: 5c9529777ee84fab428cafb07601e47204afb193
Parents: 44d6ceb
Author: Niklas Nielsen <ni...@qni.dk>
Authored: Thu May 28 12:50:32 2015 -0700
Committer: Niklas Q. Nielsen <ni...@qni.dk>
Committed: Thu May 28 12:51:01 2015 -0700

----------------------------------------------------------------------
 src/tests/mesos.hpp         |  6 ++++++
 src/tests/monitor_tests.cpp | 46 ++++++++++++++++++++++++++++++++++++++++
 2 files changed, 52 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/mesos/blob/5c952977/src/tests/mesos.hpp
----------------------------------------------------------------------
diff --git a/src/tests/mesos.hpp b/src/tests/mesos.hpp
index b8f7a2f..ac986a0 100644
--- a/src/tests/mesos.hpp
+++ b/src/tests/mesos.hpp
@@ -330,6 +330,12 @@ protected:
       DEFAULT_EXECUTOR_INFO.executor_id()
 
 
+#define DEFAULT_CONTAINER_ID                                          \
+     ({ ContainerID containerId;                                      \
+        containerId.set_value("container");                           \
+        containerId; })
+
+
 #define CREATE_COMMAND_INFO(command)                                  \
   ({ CommandInfo commandInfo;                                         \
      commandInfo.set_value(command);                                  \

http://git-wip-us.apache.org/repos/asf/mesos/blob/5c952977/src/tests/monitor_tests.cpp
----------------------------------------------------------------------
diff --git a/src/tests/monitor_tests.cpp b/src/tests/monitor_tests.cpp
index ca3b7f4..6de8b1f 100644
--- a/src/tests/monitor_tests.cpp
+++ b/src/tests/monitor_tests.cpp
@@ -37,6 +37,7 @@
 #include "slave/monitor.hpp"
 
 #include "tests/containerizer.hpp"
+#include "tests/mesos.hpp"
 
 using process::Clock;
 using process::Future;
@@ -188,6 +189,51 @@ TEST(MonitorTest, Statistics)
   AWAIT_EXPECT_RESPONSE_BODY_EQ("[]", response);
 }
 
+
+// Test for correct handling of the statistics.json endpoint when
+// monitoring of a container is stopped.
+TEST(MonitorTest, UsageFailure)
+{
+  TestContainerizer containerizer;
+
+  // Test containerizer is set up to:
+  // 1) Synchronize test with Containerizer::usage()
+  // 2) After that, stop monitoring the container.
+  Future<Nothing> usage;
+  process::Promise<ResourceStatistics> failPromise;
+  EXPECT_CALL(containerizer, usage(DEFAULT_CONTAINER_ID))
+    .WillOnce(DoAll(FutureSatisfy(&usage),
+                    Return(failPromise.future())));
+
+  slave::ResourceMonitor monitor(&containerizer);
+
+  AWAIT_READY(monitor.start(DEFAULT_CONTAINER_ID, DEFAULT_EXECUTOR_INFO));
+
+  // Induce a call to usage().
+  process::UPID upid("monitor", process::address());
+  Future<Response> response = process::http::get(upid, "statistics.json");
+
+  // Usage was called, but Future<ResourceStatistics> is still
+  // unsatisfied and monitor is blocked.
+  AWAIT_READY(usage);
+
+  // Stop monitoring the container.
+  AWAIT_READY(monitor.stop(DEFAULT_CONTAINER_ID));
+
+  // Fail the future to the collected container statistic.
+  failPromise.set(process::Failure("Injected failure"));
+
+  // Verify an empty response.
+  AWAIT_READY(response);
+
+  AWAIT_EXPECT_RESPONSE_STATUS_EQ(OK().status, response);
+  AWAIT_EXPECT_RESPONSE_HEADER_EQ(
+      "application/json",
+      "Content-Type",
+      response);
+  AWAIT_EXPECT_RESPONSE_BODY_EQ("[]", response);
+}
+
 } // namespace tests {
 } // namespace internal {
 } // namespace mesos {