From: Razvan Becheriu Date: Wed, 21 Jun 2023 16:58:44 +0000 (+0300) Subject: [#2898] added extra unittests X-Git-Tag: Kea-2.4.0~117 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2f826f475ca14f08daec856ff36d35aa3daaec32;p=thirdparty%2Fkea.git [#2898] added extra unittests --- diff --git a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc index 1e2735c522..c5d22c26f6 100644 --- a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc @@ -3009,7 +3009,9 @@ GenericLeaseMgrTest::testRecountLeaseStats4() { Pool4Ptr pool; subnet.reset(new Subnet4(IOAddress("192.0.1.0"), 24, 1, 2, 3, 1)); - pool.reset(new Pool4(IOAddress("192.0.1.0"), 24)); + pool.reset(new Pool4(IOAddress("192.0.1.0"), IOAddress("192.0.1.127"))); + subnet->addPool(pool); + pool.reset(new Pool4(IOAddress("192.0.1.128"), IOAddress("192.0.1.255"))); subnet->addPool(pool); cfg->add(subnet); @@ -3036,7 +3038,12 @@ GenericLeaseMgrTest::testRecountLeaseStats4() { ASSERT_NO_FATAL_FAILURE(checkLeaseStats(expectedStats)); // Recount stats. We should have the same results. - ASSERT_NO_THROW(lmptr_->recountLeaseStats4()); + // The call to removeStatistics is needed to clear all statistics. + // The call to updateStatistics is needed to generate all counters, + // including total-addresses. The updateStatistics method calls + // recountLeaseStats4 internally. + ASSERT_NO_THROW(cfg->removeStatistics()); + ASSERT_NO_THROW(cfg->updateStatistics()); // Make sure stats are as expected. ASSERT_NO_FATAL_FAILURE(checkLeaseStats(expectedStats)); @@ -3074,7 +3081,12 @@ GenericLeaseMgrTest::testRecountLeaseStats4() { expectedStats[subnet_id - 1]["declined-addresses"] = 1; // Now Recount the stats. - ASSERT_NO_THROW(lmptr_->recountLeaseStats4()); + // The call to removeStatistics is needed to clear all statistics. + // The call to updateStatistics is needed to generate all counters, + // including total-addresses. The updateStatistics method calls + // recountLeaseStats4 internally. + ASSERT_NO_THROW(cfg->removeStatistics()); + ASSERT_NO_THROW(cfg->updateStatistics()); // Make sure stats are as expected. ASSERT_NO_FATAL_FAILURE(checkLeaseStats(expectedStats)); @@ -3088,7 +3100,12 @@ GenericLeaseMgrTest::testRecountLeaseStats4() { expectedStats[0]["declined-addresses"] = 0; // Recount the stats. - ASSERT_NO_THROW(lmptr_->recountLeaseStats4()); + // The call to removeStatistics is needed to clear all statistics. + // The call to updateStatistics is needed to generate all counters, + // including total-addresses. The updateStatistics method calls + // recountLeaseStats4 internally. + ASSERT_NO_THROW(cfg->removeStatistics()); + ASSERT_NO_THROW(cfg->updateStatistics()); // Make sure stats are as expected. ASSERT_NO_FATAL_FAILURE(checkLeaseStats(expectedStats)); @@ -3110,6 +3127,9 @@ GenericLeaseMgrTest::testRecountLeaseStats6() { int subnet_id = 1; subnet.reset(new Subnet6(IOAddress("3001:1::"), 64, 1, 2, 3, 4, subnet_id)); pool.reset(new Pool6(Lease::TYPE_NA, IOAddress("3001:1::"), + IOAddress("3001:1::7F"))); + subnet->addPool(pool); + pool.reset(new Pool6(Lease::TYPE_NA, IOAddress("3001:1::80"), IOAddress("3001:1::FF"))); subnet->addPool(pool); expectedStats[subnet_id - 1]["total-nas"] = 256; @@ -3151,7 +3171,12 @@ GenericLeaseMgrTest::testRecountLeaseStats6() { ASSERT_NO_FATAL_FAILURE(checkLeaseStats(expectedStats)); // Recount stats. We should have the same results. - ASSERT_NO_THROW(lmptr_->recountLeaseStats6()); + // The call to removeStatistics is needed to clear all statistics. + // The call to updateStatistics is needed to generate all counters, + // including total-nas and total-pds. The updateStatistics method calls + // recountLeaseStats6 internally. + ASSERT_NO_THROW(cfg->removeStatistics()); + ASSERT_NO_THROW(cfg->updateStatistics()); // Make sure stats are as expected. ASSERT_NO_FATAL_FAILURE(checkLeaseStats(expectedStats)); @@ -3205,7 +3230,12 @@ GenericLeaseMgrTest::testRecountLeaseStats6() { expectedStats[subnet_id - 1]["declined-addresses"] = 1; // Now Recount the stats. - ASSERT_NO_THROW(lmptr_->recountLeaseStats6()); + // The call to removeStatistics is needed to clear all statistics. + // The call to updateStatistics is needed to generate all counters, + // including total-nas and total-pds. The updateStatistics method calls + // recountLeaseStats6 internally. + ASSERT_NO_THROW(cfg->removeStatistics()); + ASSERT_NO_THROW(cfg->updateStatistics()); // Make sure stats are as expected. ASSERT_NO_FATAL_FAILURE(checkLeaseStats(expectedStats)); @@ -3219,7 +3249,12 @@ GenericLeaseMgrTest::testRecountLeaseStats6() { expectedStats[1]["declined-addresses"] = 0; // Recount the stats. - ASSERT_NO_THROW(lmptr_->recountLeaseStats6()); + // The call to removeStatistics is needed to clear all statistics. + // The call to updateStatistics is needed to generate all counters, + // including total-nas and total-pds. The updateStatistics method calls + // recountLeaseStats6 internally. + ASSERT_NO_THROW(cfg->removeStatistics()); + ASSERT_NO_THROW(cfg->updateStatistics()); // Make sure stats are as expected. ASSERT_NO_FATAL_FAILURE(checkLeaseStats(expectedStats));