From: Marcin Siodelski Date: Tue, 27 Jul 2021 19:24:51 +0000 (+0200) Subject: [#1959] unsent-update-count in heartbeat response X-Git-Tag: Kea-2.0.0~84 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=a9657e4379afd25efbd9014c1560f2bed89ecb01;p=thirdparty%2Fkea.git [#1959] unsent-update-count in heartbeat response --- diff --git a/src/hooks/dhcp/high_availability/ha_service.cc b/src/hooks/dhcp/high_availability/ha_service.cc index 46d7728c36..5b5a27420f 100644 --- a/src/hooks/dhcp/high_availability/ha_service.cc +++ b/src/hooks/dhcp/high_availability/ha_service.cc @@ -1573,6 +1573,9 @@ HAService::processHeartbeat() { } arguments->set("scopes", scopes_list); + arguments->set("unsent-update-count", + Element::create(static_cast(communication_state_->getUnsentUpdateCount()))); + return (createAnswer(CONTROL_RESULT_SUCCESS, "HA peer status returned.", arguments)); } 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 f2fed405ec..3d485e54de 100644 --- a/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc @@ -2495,6 +2495,10 @@ TEST_F(HAServiceTest, processHeartbeat) { TestHAService service(io_service_, network_state_, config_storage); service.query_filter_.serveDefaultScopes(); + for (auto i = 0; i < 6; ++i) { + service.communication_state_->increaseUnsentUpdateCount(); + } + // Process heartbeat command. ConstElementPtr rsp; ASSERT_NO_THROW(rsp = service.processHeartbeat()); @@ -2538,6 +2542,14 @@ TEST_F(HAServiceTest, processHeartbeat) { // Let's allow the response propagation time of 5 seconds to make // sure this test doesn't fail on slow systems. EXPECT_LT(td.seconds(), 5); + + // The response should contain unsent-update-count parameter indicating + // how many updates haven't been sent to a partner because the partner + // was unavailable. + ConstElementPtr unsent_update_count = args->get("unsent-update-count"); + ASSERT_TRUE(unsent_update_count); + EXPECT_EQ(Element::integer, unsent_update_count->getType()); + EXPECT_EQ(6, static_cast(unsent_update_count->intValue())); } // This test verifies that the correct value of the heartbeat-delay is used.