]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3649] More unit tests
authorMarcin Siodelski <marcin@isc.org>
Thu, 5 Dec 2024 12:22:06 +0000 (13:22 +0100)
committerMarcin Siodelski <marcin@isc.org>
Thu, 23 Jan 2025 09:03:59 +0000 (09:03 +0000)
src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc

index 184f9f6facd6037c9d50916fb71ba7a1d535c318..452c49640ac55fbbe58b2faf882d4b43eee88e87 100644 (file)
@@ -9137,8 +9137,8 @@ TEST_F(HAServiceStateMachineTest, doNotTerminateWhenPartnerUnavailable) {
     EXPECT_EQ(HA_COMMUNICATION_RECOVERY_ST, service_->getCurrState());
 }
 
-// This test verifies that the service correctly identifies the leases that can
-// be reclaimed while the server is the primary.
+// This test verifies that the service reclaims the leases while the server is
+// primary and it is in the terminated state.
 TEST_F(HAServiceStateMachineTest, shouldReclaimLease4HotStandbyThisPrimary) {
     startService(createValidConfiguration(HAConfig::HOT_STANDBY));
     service_->verboseTransition(HA_TERMINATED_ST);
@@ -9148,8 +9148,19 @@ TEST_F(HAServiceStateMachineTest, shouldReclaimLease4HotStandbyThisPrimary) {
     EXPECT_TRUE(service_->shouldReclaim(lease4));
 }
 
-// This test verifies that the service correctly identifies the leases that can
-// be reclaimed while the server is the standby.
+// This test verifies that the service reclaims the leases while the server is
+// primary and it is in the non-terminated state.
+TEST_F(HAServiceStateMachineTest, shouldReclaimLease4HotStandbyThisPrimaryNotTerminated) {
+    startService(createValidConfiguration(HAConfig::HOT_STANDBY));
+    service_->verboseTransition(HA_READY_ST);
+    service_->runModel(HAService::NOP_EVT);
+
+    Lease4Ptr lease4 = createLease4(randomKey(HWAddr::ETHERNET_HWADDR_LEN));
+    EXPECT_TRUE(service_->shouldReclaim(lease4));
+}
+
+// This test verifies that the service does not reclaim the leases while the server is
+// standby and it is in the terminated state.
 TEST_F(HAServiceStateMachineTest, shouldReclaimLease4HotStandbyThisStandby) {
     HAConfigPtr valid_config = createValidConfiguration(HAConfig::HOT_STANDBY);
     valid_config->getPeerConfig("server2")->setRole("standby");
@@ -9162,8 +9173,22 @@ TEST_F(HAServiceStateMachineTest, shouldReclaimLease4HotStandbyThisStandby) {
     EXPECT_FALSE(service_->shouldReclaim(lease4));
 }
 
-// This test verifies that the service correctly identifies the leases that can
-// be reclaimed while the server is the primary.
+// This test verifies that the service reclaims the leases while the server is
+// standby and it is in the non-terminated state.
+TEST_F(HAServiceStateMachineTest, shouldReclaimLease4HotStandbyThisStandbyNotTerminated) {
+    HAConfigPtr valid_config = createValidConfiguration(HAConfig::HOT_STANDBY);
+    valid_config->getPeerConfig("server2")->setRole("standby");
+    valid_config->setThisServerName("server2");
+    startService(valid_config);
+    service_->verboseTransition(HA_READY_ST);
+    service_->runModel(HAService::NOP_EVT);
+
+    Lease4Ptr lease4 = createLease4(randomKey(HWAddr::ETHERNET_HWADDR_LEN));
+    EXPECT_TRUE(service_->shouldReclaim(lease4));
+}
+
+// This test verifies that the service reclaims the leases while the server is
+// primary and it is in the terminated state.
 TEST_F(HAServiceStateMachineTest, shouldReclaimLease6HotStandbyThisPrimary) {
     startService(createValidConfiguration(HAConfig::HOT_STANDBY));
     service_->verboseTransition(HA_TERMINATED_ST);
@@ -9173,8 +9198,19 @@ TEST_F(HAServiceStateMachineTest, shouldReclaimLease6HotStandbyThisPrimary) {
     EXPECT_TRUE(service_->shouldReclaim(lease6));
 }
 
-// This test verifies that the service correctly identifies the leases that can
-// be reclaimed while the server is the standby.
+// This test verifies that the service reclaims the leases while the server is
+// primary and it is in the non-terminated state.
+TEST_F(HAServiceStateMachineTest, shouldReclaimLease6HotStandbyThisPrimaryNotTerminated) {
+    startService(createValidConfiguration(HAConfig::HOT_STANDBY));
+    service_->verboseTransition(HA_READY_ST);
+    service_->runModel(HAService::NOP_EVT);
+
+    Lease6Ptr lease6 = createLease6(randomKey(10));
+    EXPECT_TRUE(service_->shouldReclaim(lease6));
+}
+
+// This test verifies that the service does not reclaim the leases while the server is
+// standby and it is in the terminated state.
 TEST_F(HAServiceStateMachineTest, shouldReclaimLease6HotStandbyThisStandby) {
     HAConfigPtr valid_config = createValidConfiguration(HAConfig::HOT_STANDBY);
     valid_config->getPeerConfig("server2")->setRole("standby");
@@ -9187,6 +9223,20 @@ TEST_F(HAServiceStateMachineTest, shouldReclaimLease6HotStandbyThisStandby) {
     EXPECT_FALSE(service_->shouldReclaim(lease6));
 }
 
+// This test verifies that the service reclaims the leases while the server is
+// standby and it is in the non-terminated state.
+TEST_F(HAServiceStateMachineTest, shouldReclaimLease6HotStandbyThisStandbyNotTerminated) {
+    HAConfigPtr valid_config = createValidConfiguration(HAConfig::HOT_STANDBY);
+    valid_config->getPeerConfig("server2")->setRole("standby");
+    valid_config->setThisServerName("server2");
+    startService(valid_config);
+    service_->verboseTransition(HA_READY_ST);
+    service_->runModel(HAService::NOP_EVT);
+
+    Lease6Ptr lease6 = createLease6(randomKey(10));
+    EXPECT_TRUE(service_->shouldReclaim(lease6));
+}
+
 // Test scenario when a single lease4 update is sent successfully, parking is not
 // employed.
 TEST_F(HAServiceTest, successfulSendSingleLeaseUpdateWithoutParking) {