]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#1219] Finished rebase
authorFrancis Dupont <fdupont@isc.org>
Sat, 16 May 2020 13:53:01 +0000 (15:53 +0200)
committerFrancis Dupont <fdupont@isc.org>
Sat, 16 May 2020 13:53:01 +0000 (15:53 +0200)
src/hooks/dhcp/high_availability/ha_service.cc
src/hooks/dhcp/high_availability/ha_service.h
src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc

index 52f1cf1874f973c524747b41bb6f63cf99229ee0..fa63d2a714d5f358c16118cc407c37ade13626be 100644 (file)
@@ -2248,5 +2248,28 @@ HAService::pendingRequestSize() {
     }
 }
 
+template<typename QueryPtrType>
+int
+HAService::getPendingRequest(const QueryPtrType& query) {
+    if (MultiThreadingMgr::instance().getMode()) {
+        std::lock_guard<std::mutex> lock(pending_requests_mutex_);
+        if (pending_requests_.count(query) == 0) {
+            return (0);
+        } else {
+            return (pending_requests_[query]);
+        }
+    } else {
+        if (pending_requests_.count(query) == 0) {
+            return (0);
+        } else {
+            return (pending_requests_[query]);
+        }
+    }
+}
+
+// Explicit instantiations.
+template int HAService::getPendingRequest(const Pkt4Ptr&);
+template int HAService::getPendingRequest(const Pkt6Ptr&);
+
 } // end of namespace isc::ha
 } // end of namespace isc
index 7061476f03371986cf56adb653bc665e7f61f6b5..1f2584842d1ea04bc05f287cae96a40d6cfde688 100644 (file)
@@ -946,12 +946,22 @@ protected:
     template<typename QueryPtrType>
     void updatePendingRequest(QueryPtrType& query);
 
-protected:
     /// @brief Get the number of entries in the pending request map.
     /// @note Currently for testing purposes only.
     /// @return Number of entries in the pending request map.
     size_t pendingRequestSize();
 
+    /// @brief Get the number of scheduled requests for a given query.
+    /// @note Currently for testing purposes only.
+    ///
+    /// If there is an entry in the pending request map for the given
+    /// query the entry is returned else zero is returned.
+    ///
+    /// @param query Pointer to the DHCP client's query.
+    /// @return Number of scheduled requests for the query or zero.
+    template<typename QueryPtrType>
+    int getPendingRequest(const QueryPtrType& query);
+
 private:
     /// @brief Handle last pending request for this query.
     ///
index 1d39a83c6f4fc1187c152b753d17cebb60986013..0fdf4645a5476fa685b23686d01dc9de6ae6798a 100644 (file)
@@ -190,6 +190,7 @@ public:
     using HAService::verboseTransition;
     using HAService::shouldSendLeaseUpdates;
     using HAService::pendingRequestSize;
+    using HAService::getPendingRequest;
     using HAService::network_state_;
     using HAService::config_;
     using HAService::communication_state_;
@@ -714,16 +715,11 @@ public:
                   service.asyncSendLeaseUpdates(query, leases4, deleted_leases4,
                                                 parking_lot_handle));
 
-        if (num_updates == 0) {
-            EXPECT_TRUE((service.pending_requests_.count(query) == 0) ||
-                        (service.pending_requests_[query] == 0));
-        } else {
-            // The number of pending requests should be 2 times the number of
-            // contacted servers because we send one lease update and one
-            // lease deletion to each contacted server from which we expect
-            // an acknowledgment.
-            EXPECT_EQ(2*num_updates, service.pending_requests_[query]);
-        }
+        // The number of pending requests should be 2 times the number of
+        // contacted servers because we send one lease update and one
+        // lease deletion to each contacted server from which we expect
+        // an acknowledgment.
+        EXPECT_EQ(2*num_updates, service.getPendingRequest(query));
 
         EXPECT_FALSE(state->isPoked());
 
@@ -819,15 +815,10 @@ public:
                   service.asyncSendLeaseUpdates(query, leases6, deleted_leases6,
                                                 parking_lot_handle));
 
-        if (num_updates == 0) {
-            EXPECT_TRUE((service.pending_requests_.count(query) == 0) ||
-                        (service.pending_requests_[query] == 0));
-        } else {
-            // The number of requests we send is equal to the number of servers
-            // from which we expect an acknowledgement. We send both lease updates
-            // and the deletions in a single bulk update command.
-            EXPECT_EQ(num_updates, service.pending_requests_[query]);
-        }
+        // The number of requests we send is equal to the number of servers
+        // from which we expect an acknowledgement. We send both lease updates
+        // and the deletions in a single bulk update command.
+        EXPECT_EQ(num_updates, service.getPendingRequest(query));
 
         EXPECT_FALSE(state->isPoked());