From: Francis Dupont Date: Sat, 17 Oct 2015 09:22:24 +0000 (+0200) Subject: [3978] Rearranged DHCPv4 unit tests X-Git-Tag: fdfb_base~5^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2eb98727c74304f89e678ca45d329f5644f672cb;p=thirdparty%2Fkea.git [3978] Rearranged DHCPv4 unit tests --- diff --git a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc index 89c9e93dae..961d399ad3 100644 --- a/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc +++ b/src/bin/dhcp4/tests/ctrl_dhcp4_srv_unittest.cc @@ -344,6 +344,35 @@ TEST_F(CtrlChannelDhcpv4SrvTest, controlChannelShutdown) { EXPECT_EQ("{ \"result\": 0, \"text\": \"Shutting down.\" }",response); } +// Thist test verifies that the DHCP server immediately reclaims expired +// leases on leases-reclaim command +TEST_F(CtrlChannelDhcpv4SrvTest, controlLeasesReclaim) { + createUnixChannelServer(); + + // Create an expired lease. The lease is expired by 40 seconds ago + // (valid lifetime = 60, cltt = now - 100). + HWAddrPtr hwaddr_expired(new HWAddr(HWAddr::fromText("00:01:02:03:04:05"))); + Lease4Ptr lease_expired(new Lease4(IOAddress("10.0.0.1"), hwaddr_expired, + ClientIdPtr(), 60, 10, 20, + time(NULL) - 100, SubnetID(1))); + + // Add lease to the database. + LeaseMgr& lease_mgr = LeaseMgrFactory().instance(); + ASSERT_NO_THROW(lease_mgr.addLease(lease_expired)); + + // Make sure it has been added. + ASSERT_TRUE(lease_mgr.getLease4(IOAddress("10.0.0.1"))); + + // Send the command. + std::string response; + sendUnixCommand("{ \"command\": \"leases-reclaim\" }", response); + EXPECT_EQ("{ \"result\": 0, \"text\": \"Leases successfully reclaimed.\" }", response); + + // Verify that the lease in the database has been processed as expected. + ASSERT_NO_THROW(lease_expired = lease_mgr.getLease4(IOAddress("10.0.0.1"))); + EXPECT_FALSE(lease_expired); +} + // Tests that the server properly responds to statistics commands. Note this // is really only intended to verify that the appropriate Statistics handler // is called based on the command. It is not intended to be an exhaustive @@ -390,35 +419,4 @@ TEST_F(CtrlChannelDhcpv4SrvTest, controlChannelStats) { response); } - -// Thist test verifies that the DHCP server immediately reclaims expired -// leases on leases-reclaim command -// @todo currently must be last as it changes statistics. -TEST_F(CtrlChannelDhcpv4SrvTest, controlLeasesReclaim) { - createUnixChannelServer(); - - // Create an expired lease. The lease is expired by 40 seconds ago - // (valid lifetime = 60, cltt = now - 100). - HWAddrPtr hwaddr_expired(new HWAddr(HWAddr::fromText("00:01:02:03:04:05"))); - Lease4Ptr lease_expired(new Lease4(IOAddress("10.0.0.1"), hwaddr_expired, - ClientIdPtr(), 60, 10, 20, - time(NULL) - 100, SubnetID(1))); - - // Add lease to the database. - LeaseMgr& lease_mgr = LeaseMgrFactory().instance(); - ASSERT_NO_THROW(lease_mgr.addLease(lease_expired)); - - // Make sure it has been added. - ASSERT_TRUE(lease_mgr.getLease4(IOAddress("10.0.0.1"))); - - // Send the command. - std::string response; - sendUnixCommand("{ \"command\": \"leases-reclaim\" }", response); - EXPECT_EQ("{ \"result\": 0, \"text\": \"Leases successfully reclaimed.\" }", response); - - // Verify that the lease in the database has been processed as expected. - ASSERT_NO_THROW(lease_expired = lease_mgr.getLease4(IOAddress("10.0.0.1"))); - EXPECT_FALSE(lease_expired); -} - } // End of anonymous namespace