From: Thomas Markwalder Date: Mon, 27 Apr 2026 11:17:06 +0000 (-0400) Subject: [#4466] Added concurrent pool create UT X-Git-Tag: Kea-3.1.9~133 X-Git-Url: http://git.ipfire.org/gitweb/index.cgi?a=commitdiff_plain;h=a4c0afee508351b1f3a561e59cd192d25f064745;p=thirdparty%2Fkea.git [#4466] Added concurrent pool create UT 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 --- diff --git a/src/hooks/dhcp/mysql/tests/mysql_lease_mgr_unittest.cc b/src/hooks/dhcp/mysql/tests/mysql_lease_mgr_unittest.cc index c8ff5b9efd..6ebed0452a 100644 --- a/src/hooks/dhcp/mysql/tests/mysql_lease_mgr_unittest.cc +++ b/src/hooks/dhcp/mysql/tests/mysql_lease_mgr_unittest.cc @@ -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 { diff --git a/src/hooks/dhcp/pgsql/tests/pgsql_lease_mgr_unittest.cc b/src/hooks/dhcp/pgsql/tests/pgsql_lease_mgr_unittest.cc index 36bef93da9..cfdd87c640 100644 --- a/src/hooks/dhcp/pgsql/tests/pgsql_lease_mgr_unittest.cc +++ b/src/hooks/dhcp/pgsql/tests/pgsql_lease_mgr_unittest.cc @@ -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 { diff --git a/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.cc b/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.cc index 7f07bdb68a..164d5716ee 100644 --- a/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.cc +++ b/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.cc @@ -20,6 +20,7 @@ #include #include #include +#include #include #include @@ -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 diff --git a/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.h b/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.h index 28e40faa2f..f08dceeca9 100644 --- a/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.h +++ b/src/lib/dhcpsrv/testutils/generic_lease_mgr_unittest.h @@ -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 straddress4_;