]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#3149] Added testGetLeases6SubnetIdPaged
authorFrancis Dupont <fdupont@isc.org>
Fri, 12 Jan 2024 14:35:52 +0000 (15:35 +0100)
committerFrancis Dupont <fdupont@isc.org>
Wed, 17 Jan 2024 10:06:16 +0000 (11:06 +0100)
src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc
src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.cc
src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.h

index b91c21f7231d833760552a1829c2477cb85f12d5..e0a211bddd8f69755c8bd9f64b9dc229b5703112 100644 (file)
@@ -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);
index a5737ef25368fd21a2e02e670998a7e19f8a846b..8a8fdb84f9781e642302c43cea0ce743485975f6 100644 (file)
@@ -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();
index 15eb78c4dd5028e065a9a4b13e5c787a67cad3e0..7b9e1d188ee74504b1186ed529be0f1102d36333 100644 (file)
@@ -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();
index 210ff1481ed98bfc92dd74a5d5d42738b1474d2c..bcc671097f8d7a1bf3b292e672842315699818a0 100644 (file)
@@ -1396,6 +1396,71 @@ GenericLeaseMgrTest::testGetLeases6SubnetId() {
     EXPECT_EQ(2, returned.size());
 }
 
+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.
index 2c5bfd2228c56b92e45a1b50938af058bd3abbf7..c1fe97573d681fb07d2d839339007aef6243f7f8 100644 (file)
@@ -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();