From: Marcin Siodelski Date: Thu, 5 Dec 2024 12:22:06 +0000 (+0100) Subject: [#3649] More unit tests X-Git-Tag: Kea-2.7.6~20 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=ff951d21808b1fdf515cb89a3c5eac8f07ee4cb0;p=thirdparty%2Fkea.git [#3649] More unit tests --- 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 184f9f6fac..452c49640a 100644 --- a/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc +++ b/src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc @@ -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) {