From: Razvan Becheriu Date: Thu, 4 Jun 2020 12:05:24 +0000 (+0300) Subject: [#1239] added unittests X-Git-Tag: Kea-1.7.9~64 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ebcea5488cfb5261aafb441f6abd6e056c5a01b8;p=thirdparty%2Fkea.git [#1239] added unittests --- diff --git a/src/hooks/dhcp/high_availability/tests/communication_state_unittest.cc b/src/hooks/dhcp/high_availability/tests/communication_state_unittest.cc index 6aefdaba43..265e4361f9 100644 --- a/src/hooks/dhcp/high_availability/tests/communication_state_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/communication_state_unittest.cc @@ -15,6 +15,9 @@ #include #include #include +#include + + #include #include #include @@ -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