]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1239] added unittests
authorRazvan Becheriu <razvan@isc.org>
Thu, 4 Jun 2020 12:05:24 +0000 (15:05 +0300)
committerRazvan Becheriu <razvan@isc.org>
Tue, 16 Jun 2020 09:02:52 +0000 (09:02 +0000)
src/hooks/dhcp/high_availability/tests/communication_state_unittest.cc

index 6aefdaba4337b820d18ef2f837f3cd041464a461..265e4361f97cf00e80681443ce8ef054399a1c03 100644 (file)
@@ -15,6 +15,9 @@
 #include <dhcp/dhcp6.h>
 #include <exceptions/exceptions.h>
 #include <http/date_time.h>
+#include <util/multi_threading_mgr.h>
+
+
 #include <boost/date_time/posix_time/posix_time.hpp>
 #include <boost/bind.hpp>
 #include <boost/function.hpp>
@@ -27,6 +30,8 @@ using namespace isc::dhcp;
 using namespace isc::ha;
 using namespace isc::ha::test;
 using namespace isc::http;
+using namespace isc::util;
+
 using namespace boost::posix_time;
 using namespace boost::gregorian;
 
@@ -42,10 +47,12 @@ public:
     CommunicationStateTest()
         : state_(io_service_, createValidConfiguration()),
           state6_(io_service_, createValidConfiguration()) {
+        MultiThreadingMgr::instance().setMode(false);
     }
 
     /// @brief Destructor.
     ~CommunicationStateTest() {
+        MultiThreadingMgr::instance().setMode(false);
         io_service_->poll();
     }
 
@@ -156,6 +163,17 @@ TEST_F(CommunicationStateTest, poke) {
     EXPECT_FALSE(state_.isCommunicationInterrupted());
 }
 
+// Verifies that  poking the state updates the returned duration.
+TEST_F(CommunicationStateTest, pokeMultiThreading) {
+    MultiThreadingMgr::instance().setMode(true);
+    state_.modifyPokeTime(-30);
+    ASSERT_GE(state_.getDurationInMillisecs(), 30000);
+    ASSERT_TRUE(state_.isCommunicationInterrupted());
+    ASSERT_NO_THROW(state_.poke());
+    EXPECT_TRUE(state_.isPoked());
+    EXPECT_FALSE(state_.isCommunicationInterrupted());
+}
+
 // Test that heartbeat function is triggered.
 TEST_F(CommunicationStateTest, heartbeat) {
     // Set poke time to the past and expect that the object is considered