]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#2089] added ncr unittests
authorRazvan Becheriu <razvan@isc.org>
Thu, 7 Oct 2021 17:26:38 +0000 (20:26 +0300)
committerRazvan Becheriu <razvan@isc.org>
Fri, 8 Oct 2021 11:47:19 +0000 (11:47 +0000)
src/bin/d2/tests/d2_queue_mgr_unittests.cc
src/lib/dhcp_ddns/ncr_udp.cc

index a00de29f4bd7013a23efebd3596798740a91627d..d2d41f5e5639e3eb52040ad8aa89f33be40c8a4a 100644 (file)
@@ -9,6 +9,7 @@
 #include <asiolink/io_service.h>
 #include <asiolink/interval_timer.h>
 #include <d2/d2_queue_mgr.h>
+#include <d2srv/testutils/stats_test_utils.h>
 #include <dhcp_ddns/ncr_udp.h>
 #include <util/time_utilities.h>
 
@@ -21,6 +22,7 @@ using namespace std;
 using namespace isc;
 using namespace isc::dhcp_ddns;
 using namespace isc::d2;
+using namespace isc::d2::test;
 
 namespace {
 
@@ -203,7 +205,7 @@ bool checkSendVsReceived(NameChangeRequestPtr sent_ncr,
 /// @brief Text fixture that allows testing a listener and sender together
 /// It derives from both the receive and send handler classes and contains
 /// and instance of UDP listener and UDP sender.
-class QueueMgrUDPTest : public virtual ::testing::Test,
+class QueueMgrUDPTest : public virtual ::testing::Test, public D2StatTest,
                         NameChangeSender::RequestSendHandler {
 public:
     asiolink::IOServicePtr io_service_;
@@ -384,6 +386,13 @@ TEST_F (QueueMgrUDPTest, liveFeed) {
         EXPECT_EQ(0, queue_mgr_->getQueueSize());
     }
 
+    StatMap stats_ncr = {
+        { "ncr-received", 3},
+        { "ncr-invalid", 0},
+        { "ncr-error", 0}
+    };
+    checkStats(stats_ncr);
+
     // Iterate over the list of requests, sending and receiving
     // each one. Allow them to accumulate in the queue.
     for (int i = 0; i < VALID_MSG_CNT; i++) {
@@ -397,6 +406,13 @@ TEST_F (QueueMgrUDPTest, liveFeed) {
         EXPECT_EQ(i+1, queue_mgr_->getQueueSize());
     }
 
+    StatMap stats_ncr_new = {
+        { "ncr-received", 6},
+        { "ncr-invalid", 0},
+        { "ncr-error", 0}
+    };
+    checkStats(stats_ncr_new);
+
     // Verify that the queue is at max capacity.
     EXPECT_EQ(queue_mgr_->getMaxQueueSize(), queue_mgr_->getQueueSize());
 
@@ -428,7 +444,6 @@ TEST_F (QueueMgrUDPTest, liveFeed) {
     EXPECT_NO_THROW(queue_mgr_->clearQueue());
     EXPECT_EQ(0, queue_mgr_->getQueueSize());
 
-
     // Verify that we can again receive requests.
     // Send should be fine.
     ASSERT_NO_THROW(sender_->sendRequest(send_ncr));
index fc46f5b651b8dacde2c5136e1b77ae3ff24d5943..43629d18188ca274ff5703b8eaaee032236e5032 100644 (file)
@@ -163,12 +163,12 @@ NameChangeUDPListener::receiveCompletionHandler(const bool successful,
         try {
             ncr = NameChangeRequest::fromFormat(format_, input_buffer);
             isc::stats::StatsMgr::instance().addValue("ncr-received",
-                                                      static_cast<int64_t>(0));
+                                                      static_cast<int64_t>(1));
         } catch (const NcrMessageError& ex) {
             // log it and go back to listening
             LOG_ERROR(dhcp_ddns_logger, DHCP_DDNS_INVALID_NCR).arg(ex.what());
             isc::stats::StatsMgr::instance().addValue("ncr-invalid",
-                                                      static_cast<int64_t>(0));
+                                                      static_cast<int64_t>(1));
 
             // Queue up the next receive.
             // NOTE: We must call the base class, NEVER doReceive
@@ -187,7 +187,7 @@ NameChangeUDPListener::receiveCompletionHandler(const bool successful,
             LOG_ERROR(dhcp_ddns_logger, DHCP_DDNS_NCR_UDP_RECV_ERROR)
                       .arg(error_code.message());
             isc::stats::StatsMgr::instance().addValue("ncr-error",
-                                                      static_cast<int64_t>(0));
+                                                      static_cast<int64_t>(1));
             result = ERROR;
         }
     }