From: Francis Dupont Date: Sat, 16 May 2020 13:53:01 +0000 (+0200) Subject: [#1219] Finished rebase X-Git-Tag: Kea-1.7.8~79 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=68667a10a970b91fe5e1229c352dd76003439c5d;p=thirdparty%2Fkea.git [#1219] Finished rebase --- diff --git a/src/hooks/dhcp/high_availability/ha_service.cc b/src/hooks/dhcp/high_availability/ha_service.cc index 52f1cf1874..fa63d2a714 100644 --- a/src/hooks/dhcp/high_availability/ha_service.cc +++ b/src/hooks/dhcp/high_availability/ha_service.cc @@ -2248,5 +2248,28 @@ HAService::pendingRequestSize() { } } +template +int +HAService::getPendingRequest(const QueryPtrType& query) { + if (MultiThreadingMgr::instance().getMode()) { + std::lock_guard 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 diff --git a/src/hooks/dhcp/high_availability/ha_service.h b/src/hooks/dhcp/high_availability/ha_service.h index 7061476f03..1f2584842d 100644 --- a/src/hooks/dhcp/high_availability/ha_service.h +++ b/src/hooks/dhcp/high_availability/ha_service.h @@ -946,12 +946,22 @@ protected: template 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 + int getPendingRequest(const QueryPtrType& query); + private: /// @brief Handle last pending request for this query. /// diff --git a/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc b/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc index 1d39a83c6f..0fdf4645a5 100644 --- a/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc @@ -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());