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 2012/11/04 02:29:40 UTC

svn commit: r1405462 - in /incubator/mesos/branches/0.10.0/src/tests: utils.hpp zookeeper_tests.cpp

Author: benh
Date: Sun Nov  4 01:29:40 2012
New Revision: 1405462

URL: http://svn.apache.org/viewvc?rev=1405462&view=rev
Log:
*** MODIFIED FOR 0.10.0 ***
Added a test that expects a _contending_ MasterDetector instance will
send a NoMasterDetected message to the listening PID
(https://reviews.apache.org/r/7293).

Modified:
    incubator/mesos/branches/0.10.0/src/tests/utils.hpp
    incubator/mesos/branches/0.10.0/src/tests/zookeeper_tests.cpp

Modified: incubator/mesos/branches/0.10.0/src/tests/utils.hpp
URL: http://svn.apache.org/viewvc/incubator/mesos/branches/0.10.0/src/tests/utils.hpp?rev=1405462&r1=1405461&r2=1405462&view=diff
==============================================================================
--- incubator/mesos/branches/0.10.0/src/tests/utils.hpp (original)
+++ incubator/mesos/branches/0.10.0/src/tests/utils.hpp Sun Nov  4 01:29:40 2012
@@ -19,6 +19,8 @@
 #ifndef __TESTING_UTILS_HPP__
 #define __TESTING_UTILS_HPP__
 
+#include <unistd.h> // For usleep.
+
 #include <gmock/gmock.h>
 
 #include <map>
@@ -33,6 +35,7 @@
 
 #include <stout/option.hpp>
 #include <stout/os.hpp>
+#include <stout/time.hpp>
 
 #include "common/type_utils.hpp"
 
@@ -447,21 +450,20 @@ ACTION_P(SendStatusUpdateFromTaskID, sta
 
 
 /**
- * This macro can be used to wait until some expression evaluates to
- * true. Currently, a test will wait no longer than approxiamtely 2
- * seconds (10 us * 200000). At some point we may add a mechanism to
- * specify how long to try and wait.
+ * These macros can be used to wait until some expression evaluates to true.
  */
-#define WAIT_UNTIL(e)                                                   \
+#define WAIT_FOR(expression, duration)                                  \
   do {                                                                  \
-    int sleeps = 0;                                                     \
+    unsigned int sleeps = 0;                                            \
     do {                                                                \
       __sync_synchronize();                                             \
-      if (e)                                                            \
+      if (expression) {                                                 \
         break;                                                          \
+      }                                                                 \
       usleep(10);                                                       \
-      if (sleeps++ >= 200000) {                                         \
-        FAIL() << "Waited too long for '" #e "'";                       \
+      sleeps++;                                                         \
+      if (microseconds(10 * sleeps).value >= ((microseconds) duration).value) { \
+        FAIL() << "Waited too long for '" #expression "'";              \
         ::exit(-1); /* TODO(benh): Figure out how not to exit! */       \
         break;                                                          \
       }                                                                 \
@@ -469,6 +471,10 @@ ACTION_P(SendStatusUpdateFromTaskID, sta
   } while (false)
 
 
+#define WAIT_UNTIL(expression)                  \
+  WAIT_FOR(expression, seconds(2.0))
+
+
 class TestingIsolationModule : public slave::IsolationModule
 {
 public:

Modified: incubator/mesos/branches/0.10.0/src/tests/zookeeper_tests.cpp
URL: http://svn.apache.org/viewvc/incubator/mesos/branches/0.10.0/src/tests/zookeeper_tests.cpp?rev=1405462&r1=1405461&r2=1405462&view=diff
==============================================================================
--- incubator/mesos/branches/0.10.0/src/tests/zookeeper_tests.cpp (original)
+++ incubator/mesos/branches/0.10.0/src/tests/zookeeper_tests.cpp Sun Nov  4 01:29:40 2012
@@ -18,21 +18,31 @@
 
 #include <zookeeper.h>
 
-#include <string>
+#include <gmock/gmock.h>
 
-#include <gtest/gtest.h>
+#include <string>
 
+#include <process/clock.hpp>
 #include <process/process.hpp>
+#include <process/protobuf.hpp>
 
+#include <stout/time.hpp>
 #include <stout/try.hpp>
 
 #include "detector/detector.hpp"
 
+#include "messages/messages.hpp"
+
 #include "tests/base_zookeeper_test.hpp"
 
 #include "zookeeper/authentication.hpp"
 #include "zookeeper/group.hpp"
 
+using process::Clock;
+
+using testing::_;
+using testing::Return;
+
 
 class ZooKeeperTest : public mesos::internal::test::BaseZooKeeperTest {
 protected:
@@ -159,6 +169,11 @@ TEST_F(ZooKeeperTest, MasterDetectors)
 
   WAIT_UNTIL(newMasterDetectedCall2);
 
+  // Destroying detector1 (below) might cause another election so we
+  // need to set up expectations appropriately.
+  EXPECT_CALL(mock2, newMasterDetected(_))
+    .WillRepeatedly(Return());
+
   MasterDetector::destroy(detector1.get());
 
   process::terminate(mock1);
@@ -171,6 +186,53 @@ TEST_F(ZooKeeperTest, MasterDetectors)
 }
 
 
+TEST_F(ZooKeeperTest, MasterDetectorShutdownNetwork)
+{
+  Clock::pause();
+
+  MockMasterDetectorListenerProcess mock;
+  process::spawn(mock);
+
+  trigger newMasterDetectedCall1;
+  EXPECT_CALL(mock, newMasterDetected(mock.self()))
+    .WillOnce(Trigger(&newMasterDetectedCall1));
+
+  std::string master = "zk://" + zks->connectString() + "/mesos";
+
+  Try<MasterDetector*> detector =
+    MasterDetector::create(master, mock.self(), true, true);
+
+  EXPECT_TRUE(detector.isSome()) << detector.error();
+
+  WAIT_UNTIL(newMasterDetectedCall1);
+
+  trigger noMasterDetectedCall;
+  EXPECT_CALL(mock, noMasterDetected())
+    .WillOnce(Trigger(&noMasterDetectedCall));
+
+  zks->shutdownNetwork();
+
+  Clock::advance(10.0); // TODO(benh): Get session timeout from detector.
+
+  WAIT_UNTIL(noMasterDetectedCall);
+
+  trigger newMasterDetectedCall2;
+  EXPECT_CALL(mock, newMasterDetected(mock.self()))
+    .WillOnce(Trigger(&newMasterDetectedCall2));
+
+  zks->startNetwork();
+
+  WAIT_FOR(newMasterDetectedCall2, seconds(5.0));
+
+  MasterDetector::destroy(detector.get());
+
+  process::terminate(mock);
+  process::wait(mock);
+
+  Clock::resume();
+}
+
+
 TEST_F(ZooKeeperTest, Group)
 {
   zookeeper::Group group(zks->connectString(), NO_TIMEOUT, "/test/");