]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4466] Added concurrent pool create UT
authorThomas Markwalder <tmark@isc.org>
Mon, 27 Apr 2026 11:17:06 +0000 (07:17 -0400)
committerThomas Markwalder <tmark@isc.org>
Mon, 4 May 2026 15:32:33 +0000 (15:32 +0000)
modified:   src/hooks/dhcp/mysql/tests/mysql_lease_mgr_unittest.cc
modified:   src/hooks/dhcp/pgsql/tests/pgsql_lease_mgr_unittest.cc
modified:   src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.cc
modified:   src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.h

src/hooks/dhcp/mysql/tests/mysql_lease_mgr_unittest.cc
src/hooks/dhcp/pgsql/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 c8ff5b9efdd923d81ba2577ef012abe6c3797692..6ebed0452a25c350a546254732a4f126256a75f5 100644 (file)
@@ -1486,6 +1486,14 @@ TEST_F(MySqlLeaseMgrTest, testSflqAPIOverlappingPools6PD) {
     testSflqAPIOverlappingPools6(Lease::TYPE_PD);
 }
 
+TEST_F(MySqlLeaseMgrTest, sflqCreateFlqPool4Concurrent) {
+    sflqCreateFlqPool4Concurrent();
+}
+
+TEST_F(MySqlLeaseMgrTest, sflqCreateFlqPool6Concurrent) {
+    sflqCreateFlqPool6Concurrent();
+}
+
 /// @brief Test fixture class for testing @ref CfgDbAccessTest using MySQL
 /// backend.
 class CfgMySqlLbDbAccessTest : public ::testing::Test {
index 36bef93da9cb488ea2ffa44f6a19737bfb1fa902..cfdd87c640253f53f4ba301a5fb506cefcad637d 100644 (file)
@@ -1450,6 +1450,16 @@ TEST_F(PgSqlLeaseMgrTest, testSflqAPIOverlappingPools6PD) {
     testSflqAPIOverlappingPools6(Lease::TYPE_PD);
 }
 
+TEST_F(PgSqlLeaseMgrTest, sflqCreateFlqPool4Concurrent) {
+    sflqCreateFlqPool4Concurrent();
+}
+
+TEST_F(PgSqlLeaseMgrTest, sflqCreateFlqPool6Concurrent) {
+    sflqCreateFlqPool6Concurrent();
+}
+
+
+
 /// @brief Test fixture class for testing @ref CfgDbAccessTest using PostgreSQL
 /// backend.
 class CfgPgSqlLbDbAccessTest : public ::testing::Test {
index 7f07bdb68a72639f9255611cd047c979d29898a3..164d5716ee3cb648de948856a26f91f6bfed5ca8 100644 (file)
@@ -20,6 +20,7 @@
 #include <stats/testutils/stats_test_utils.h>
 #include <testutils/gtest_utils.h>
 #include <util/bigints.h>
+#include <testutils/multi_threading_utils.h>
 
 #include <boost/range/adaptor/reversed.hpp>
 #include <boost/scoped_ptr.hpp>
@@ -6590,6 +6591,78 @@ GenericLeaseMgrTest::testSflqAPIOverlappingPools6(Lease::Type lease_type) {
     checkPoolInfos(*(*pool_infos)[1], *test_pools[2], __LINE__);
 }
 
+void
+GenericLeaseMgrTest::sflqCreateFlqPool4Concurrent() {
+    // Enable Multi-Threading.
+    isc::test::MultiThreadingTest mt(true);
+
+    // Create the same pool in different threads.
+    bool ret1 = false;
+    bool ret2 = false;
+    IOAddress start_address("192.0.0.0");
+    IOAddress end_address("192.0.255.255");
+    thread th1([this, &ret1, start_address, end_address]() {
+            ASSERT_NO_THROW_LOG(ret1 =
+                lmptr_->sflqCreateFlqPool4(start_address, end_address, false));
+    });
+
+    usleep(1000);
+    thread th2([this, &ret2, start_address, end_address]() {
+            ASSERT_NO_THROW_LOG(ret2 =
+                lmptr_->sflqCreateFlqPool4(start_address, end_address, false));
+    });
+
+    th1.join();
+    th2.join();
+
+    // One thread should create the pool, the other should not.
+    ASSERT_NE(ret1, ret2);
+
+    // Verify the pool and free leases were created.
+    SflqPoolInfoCollectionPtr pool_infos;
+    ASSERT_NO_THROW_LOG(pool_infos = lmptr_->sflqPool4Get(start_address, end_address));
+    ASSERT_TRUE(pool_infos);
+    ASSERT_EQ(1, pool_infos->size());
+    ASSERT_EQ(65536, (*pool_infos)[0]->free_leases_);
+}
+
+void
+GenericLeaseMgrTest::sflqCreateFlqPool6Concurrent() {
+    // Enable Multi-Threading.
+    isc::test::MultiThreadingTest mt(true);
+
+    // Create the same pool in different threads.
+    bool ret1 = false;
+    bool ret2 = false;
+    IOAddress start_address("3001::");
+    IOAddress end_address("3001::FFFF");
+    thread th1([this, &ret1, start_address, end_address]() {
+            ASSERT_NO_THROW_LOG(ret1 =
+                lmptr_->sflqCreateFlqPool6(start_address, end_address,
+                                           Lease::TYPE_NA, 128, 1, false));
+    });
+
+    thread th2([this, &ret2, start_address, end_address]() {
+            ASSERT_NO_THROW_LOG(ret2 =
+                lmptr_->sflqCreateFlqPool6(start_address, end_address,
+                                           Lease::TYPE_NA, 128, 1, false));
+    });
+
+    th1.join();
+    th2.join();
+
+    // One thread should create the pool, the other should not.
+    ASSERT_NE(ret1, ret2);
+
+
+    // Verify the pool and free leases were created.
+    SflqPoolInfoCollectionPtr pool_infos;
+    ASSERT_NO_THROW_LOG(pool_infos = lmptr_->sflqPool6Get(start_address, end_address));
+    ASSERT_TRUE(pool_infos);
+    ASSERT_EQ(1, pool_infos->size());
+    ASSERT_EQ(65536, (*pool_infos)[0]->free_leases_);
+}
+
 }  // namespace test
 }  // namespace dhcp
 }  // namespace isc
index 28e40faa2ffd9e14e3ec7380a96736e803d446ab..f08dceeca99cb9770b6f912e90418308b3d1f44c 100644 (file)
@@ -740,6 +740,14 @@ public:
     /// @param lease_type lease type to test (TYPE_NA or TYPE_PD)
     void testSflqAPIOverlappingPools6(Lease::Type lease_type);
 
+    /// @brief Verifies concurrent calls to create the same V4 SFLQ pool
+    /// work correctly.
+    void sflqCreateFlqPool4Concurrent();
+
+    /// @brief Verifies concurrent calls to create the same V6 SFLQ pool
+    /// work correctly.
+    void sflqCreateFlqPool6Concurrent();
+
     /// @brief String forms of IPv4 addresses
     std::vector<std::string> straddress4_;