Skip to content

Commit

Permalink
[#3649] More unit tests
Browse files Browse the repository at this point in the history
  • Loading branch information
msiodelski committed Jan 23, 2025
1 parent 63b0786 commit ff951d2
Showing 1 changed file with 58 additions and 8 deletions.
66 changes: 58 additions & 8 deletions src/hooks/dhcp/high_availability/tests/ha_service_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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");
Expand All @@ -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);
Expand All @@ -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");
Expand All @@ -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) {
Expand Down

0 comments on commit ff951d2

Please sign in to comment.