diff options
author | Francis Dupont <fdupont@isc.org> | 2024-01-12 15:35:52 +0100 |
---|---|---|
committer | Francis Dupont <fdupont@isc.org> | 2024-01-17 11:06:16 +0100 |
commit | d84201cb87a468236e2ce3bf3783ec6903c869ad (patch) | |
tree | b6ce6633e0a9f708ef40adc104f8682d6cfba7d3 | |
parent | [#3149] Moved to getLeases6 overload (diff) | |
download | kea-d84201cb87a468236e2ce3bf3783ec6903c869ad.tar.xz kea-d84201cb87a468236e2ce3bf3783ec6903c869ad.zip |
[#3149] Added testGetLeases6SubnetIdPaged
5 files changed, 110 insertions, 0 deletions
diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc index b91c21f723..e0a211bddd 100644 --- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc @@ -1103,6 +1103,21 @@ TEST_F(MemfileLeaseMgrTest, getLeases6SubnetIdMultiThread) { testGetLeases6SubnetId(); } +/// @brief This test checks that all IPv6 leases for a specified subnet id +/// with paging are returned. +TEST_F(MemfileLeaseMgrTest, getLeases6SubnetIdPaged) { + startBackend(V6); + testGetLeases6SubnetIdPaged(); +} + +/// @brief This test checks that all IPv6 leases for a specified subnet id +/// with paging are returned. +TEST_F(MemfileLeaseMgrTest, getLeases6SubnetIdPagedMultiThread) { + startBackend(V6); + MultiThreadingMgr::instance().setMode(true); + testGetLeases6SubnetIdPaged(); +} + /// @brief This test checks that all IPv6 leases with a specified hostname are returned. TEST_F(MemfileLeaseMgrTest, getLeases6Hostname) { startBackend(V6); diff --git a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc index a5737ef253..8a8fdb84f9 100644 --- a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc @@ -534,6 +534,19 @@ TEST_F(MySqlLeaseMgrTest, getLeases6SubnetIdMultiThreading) { testGetLeases6SubnetId(); } +/// @brief This test checks that all IPv6 leases for a specified subnet id +/// with paging are returned. +TEST_F(MySqlLeaseMgrTest, getLeases6SubnetIdPaged) { + testGetLeases6SubnetIdPaged(); +} + +/// @brief This test checks that all IPv6 leases for a specified subnet id +/// with paging are returned. +TEST_F(MySqlLeaseMgrTest, getLeases6SubnetIdPagedMultiThreading) { + MultiThreadingTest mt(true); + testGetLeases6SubnetIdPaged(); +} + /// @brief This test checks that all IPv6 leases with a specified hostname are returned. TEST_F(MySqlLeaseMgrTest, getLeases6Hostname) { testGetLeases6Hostname(); diff --git a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc index 15eb78c4dd..7b9e1d188e 100644 --- a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc @@ -501,6 +501,19 @@ TEST_F(PgSqlLeaseMgrTest, getLeases6SubnetIdMultiThreading) { testGetLeases6SubnetId(); } +/// @brief This test checks that all IPv6 leases for a specified subnet id +/// with paging are returned. +TEST_F(PgSqlLeaseMgrTest, getLeases6SubnetIdPaged) { + testGetLeases6SubnetIdPaged(); +} + +/// @brief This test checks that all IPv6 leases for a specified subnet id +/// with paging are returned. +TEST_F(PgSqlLeaseMgrTest, getLeases6SubnetIdPagedMultiThreading) { + MultiThreadingTest mt(true); + testGetLeases6SubnetIdPaged(); +} + /// @brief This test checks that all IPv6 leases with a specified hostname are returned. TEST_F(PgSqlLeaseMgrTest, getLeases6Hostname) { testGetLeases6Hostname(); diff --git a/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.cc b/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.cc index 210ff1481e..bcc671097f 100644 --- a/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.cc @@ -1397,6 +1397,71 @@ GenericLeaseMgrTest::testGetLeases6SubnetId() { } void +GenericLeaseMgrTest::testGetLeases6SubnetIdPaged() { + // Get the leases to be used for the test. + vector<Lease6Ptr> leases = createLeases6(); + // Put them in subnet 111 at the exception of the third. + for (size_t i = 0; i < leases.size(); ++i) { + if (i == 3) { + continue; + } + leases[i]->subnet_id_ = 111; + } + // Add them to the database. + for (size_t i = 0; i < leases.size(); ++i) { + EXPECT_TRUE(lmptr_->addLease(leases[i])); + } + + // Code copied from testGetLeases6Paged. + Lease6Collection all_leases; + + IOAddress last_address = IOAddress::IPV6_ZERO_ADDRESS(); + for (auto i = 0; i < 4; ++i) { + Lease6Collection page = lmptr_->getLeases6(111, last_address, + LeasePageSize(3)); + + // Collect leases in a common structure. + for (Lease6Ptr lease : page) { + all_leases.push_back(lease); + } + + // Empty page means there are no more leases. + if (page.empty()) { + break; + } else { + // Record last returned address because it is going to be used + // as an argument for the next call. + last_address = page[page.size() - 1]->addr_; + } + } + + // Make sure that we got exactly the expected number of leases. + EXPECT_EQ(leases.size(), all_leases.size() + 1); + + // Make sure that all leases that we stored in the lease database + // have been retrieved at the exception of the third. + for (Lease6Ptr lease : leases) { + if (lease == leases[3]) { + continue; + } + bool found = false; + for (Lease6Ptr returned_lease : all_leases) { + if (lease->addr_ == returned_lease->addr_) { + found = true; + break; + } + } + EXPECT_TRUE(found) << "lease for address " << lease->addr_.toText() + << " was not returned in any of the pages"; + } + + // Only IPv6 address can be used. + EXPECT_THROW(lmptr_->getLeases6(111, IOAddress("192.0.2.0"), + LeasePageSize(3)), + InvalidAddressFamily); +} + +void GenericLeaseMgrTest::testGetLeases6Hostname() { // Get the leases to be used for the test and add to the database. vector<Lease6Ptr> leases = createLeases6(); diff --git a/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.h b/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.h index 2c5bfd2228..c1fe97573d 100644 --- a/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.h +++ b/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.h @@ -264,6 +264,10 @@ public: /// @brief Test method which returns all IPv6 leases for Subnet ID. void testGetLeases6SubnetId(); + /// @brief Test method which returns all IPv6 leases for Subnet ID + /// with paging. + void testGetLeases6SubnetIdPaged(); + /// @brief Test method which returns all IPv6 leases for Hostname. void testGetLeases6Hostname(); |