summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv/tests
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/dhcpsrv/tests')
-rw-r--r--src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc248
-rw-r--r--src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h64
-rw-r--r--src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc113
-rw-r--r--src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc106
-rw-r--r--src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc106
-rw-r--r--src/lib/dhcpsrv/tests/tracking_lease_mgr_unittest.cc57
6 files changed, 653 insertions, 41 deletions
diff --git a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc
index 3ea4ad7169..8f6a1720bd 100644
--- a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.cc
@@ -23,6 +23,7 @@
#include <gtest/gtest.h>
+#include <functional>
#include <limits>
#include <sstream>
@@ -2945,9 +2946,10 @@ GenericLeaseMgrTest::makeLease6(const Lease::Type& type,
}
void
-GenericLeaseMgrTest::logCallback(const TrackingLeaseMgr::CallbackType type, SubnetID subnet_id,
- const LeasePtr& lease) {
- logs_.push_back(Log{type, subnet_id, lease});
+GenericLeaseMgrTest::logCallback(TrackingLeaseMgr::CallbackType type, SubnetID subnet_id,
+ LeasePtr lease, bool mt_safe) {
+ auto locked = (lmptr_ ? lmptr_->isLocked(lease) : false);
+ logs_.push_back(Log{type, subnet_id, lease, mt_safe, locked});
}
int
@@ -4157,6 +4159,246 @@ GenericLeaseMgrTest::testClassLeaseCount6(Lease::Type ltype) {
ASSERT_FALSE(lease);
}
+void
+GenericLeaseMgrTest::testTrackAddLease4(bool expect_locked, bool expect_mt_safe) {
+ // Register a callback for all subnets.
+ lmptr_->registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, 0, "flq",
+ std::bind(&GenericLeaseMgrTest::logCallback,
+ this,
+ TrackingLeaseMgr::TRACK_ADD_LEASE,
+ 0,
+ ph::_1,
+ ph::_2));
+ // Add a lease. It should trigger the callback.
+ Lease4Ptr lease = initializeLease4(straddress4_[1]);
+ EXPECT_TRUE(lmptr_->addLease(lease));
+
+ // Make sure that the callback has been invoked.
+ ASSERT_EQ(1, logs_.size());
+
+ // This flag should be false for the Memfile backend and true
+ // for the SQL backends.
+ if (expect_locked) {
+ EXPECT_TRUE(logs_[0].locked);
+ } else {
+ EXPECT_FALSE(logs_[0].locked);
+ }
+ // This flag should be set to true for the Memfile backends.
+ // It should be false for other backends. If the backends do
+ // not provide the MT-safe context, the callbacks must protect
+ // against the concurrent access on their own.
+ if (expect_mt_safe) {
+ EXPECT_TRUE(logs_[0].mt_safe);
+ } else {
+ EXPECT_FALSE(logs_[0].mt_safe);
+ }
+
+ // The lease locks should have been released.
+ EXPECT_FALSE(lmptr_->isLocked(lease));
+}
+
+void
+GenericLeaseMgrTest::testTrackAddLease6(bool expect_locked, bool expect_mt_safe) {
+ // Register a callback for all subnets.
+ lmptr_->registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, 0, "flq",
+ std::bind(&GenericLeaseMgrTest::logCallback,
+ this,
+ TrackingLeaseMgr::TRACK_ADD_LEASE,
+ 0,
+ ph::_1,
+ ph::_2));
+ // Add a lease. It should trigger the callback.
+ Lease6Ptr lease = initializeLease6(straddress6_[1]);
+ EXPECT_TRUE(lmptr_->addLease(lease));
+
+ // Make sure that the callback has been invoked.
+ ASSERT_EQ(1, logs_.size());
+
+ // This flag should be false for the Memfile backend and true
+ // for the SQL backends.
+ if (expect_locked) {
+ EXPECT_TRUE(logs_[0].locked);
+ } else {
+ EXPECT_FALSE(logs_[0].locked);
+ }
+ // This flag should be set to true for the Memfile backends.
+ // It should be false for other backends. If the backends do
+ // not provide the MT-safe context, the callbacks must protect
+ // against the concurrent access on their own.
+ if (expect_mt_safe) {
+ EXPECT_TRUE(logs_[0].mt_safe);
+ } else {
+ EXPECT_FALSE(logs_[0].mt_safe);
+ }
+
+ // The lease locks should have been released.
+ EXPECT_FALSE(lmptr_->isLocked(lease));
+}
+
+void
+GenericLeaseMgrTest::testTrackUpdateLease4(bool expect_locked, bool expect_mt_safe) {
+ // Register a callback for all subnets.
+ lmptr_->registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, 0, "flq",
+ std::bind(&GenericLeaseMgrTest::logCallback,
+ this,
+ TrackingLeaseMgr::TRACK_UPDATE_LEASE,
+ 0,
+ ph::_1,
+ ph::_2));
+ // Add a lease.
+ Lease4Ptr lease = initializeLease4(straddress4_[1]);
+ EXPECT_TRUE(lmptr_->addLease(lease));
+ EXPECT_TRUE(logs_.empty());
+
+ lmptr_->updateLease4(lease);
+
+ // Make sure that the callback has been invoked.
+ ASSERT_EQ(1, logs_.size());
+
+ // This flag should be false for the Memfile backend and true
+ // for the SQL backends.
+ if (expect_locked) {
+ EXPECT_TRUE(logs_[0].locked);
+ } else {
+ EXPECT_FALSE(logs_[0].locked);
+ }
+ // This flag should be set to true for the Memfile backends.
+ // It should be false for other backends. If the backends do
+ // not provide the MT-safe context, the callbacks must protect
+ // against the concurrent access on their own.
+ if (expect_mt_safe) {
+ EXPECT_TRUE(logs_[0].mt_safe);
+ } else {
+ EXPECT_FALSE(logs_[0].mt_safe);
+ }
+
+ // The lease locks should have been released.
+ EXPECT_FALSE(lmptr_->isLocked(lease));
+}
+
+void
+GenericLeaseMgrTest::testTrackUpdateLease6(bool expect_locked, bool expect_mt_safe) {
+ // Register a callback for all subnets.
+ lmptr_->registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, 0, "flq",
+ std::bind(&GenericLeaseMgrTest::logCallback,
+ this,
+ TrackingLeaseMgr::TRACK_UPDATE_LEASE,
+ 0,
+ ph::_1,
+ ph::_2));
+ // Add a lease.
+ Lease6Ptr lease = initializeLease6(straddress6_[1]);
+ EXPECT_TRUE(lmptr_->addLease(lease));
+ EXPECT_TRUE(logs_.empty());
+
+ lmptr_->updateLease6(lease);
+
+ // Make sure that the callback has been invoked.
+ ASSERT_EQ(1, logs_.size());
+
+ // This flag should be false for the Memfile backend and true
+ // for the SQL backends.
+ if (expect_locked) {
+ EXPECT_TRUE(logs_[0].locked);
+ } else {
+ EXPECT_FALSE(logs_[0].locked);
+ }
+ // This flag should be set to true for the Memfile backends.
+ // It should be false for other backends. If the backends do
+ // not provide the MT-safe context, the callbacks must protect
+ // against the concurrent access on their own.
+ if (expect_mt_safe) {
+ EXPECT_TRUE(logs_[0].mt_safe);
+ } else {
+ EXPECT_FALSE(logs_[0].mt_safe);
+ }
+
+ // The lease locks should have been released.
+ EXPECT_FALSE(lmptr_->isLocked(lease));
+}
+
+void
+GenericLeaseMgrTest::testTrackDeleteLease4(bool expect_locked, bool expect_mt_safe) {
+ // Register a callback for all subnets.
+ lmptr_->registerCallback(TrackingLeaseMgr::TRACK_DELETE_LEASE, 0, "flq",
+ std::bind(&GenericLeaseMgrTest::logCallback,
+ this,
+ TrackingLeaseMgr::TRACK_DELETE_LEASE,
+ 0,
+ ph::_1,
+ ph::_2));
+ // Add a lease.
+ Lease4Ptr lease = initializeLease4(straddress4_[1]);
+ EXPECT_TRUE(lmptr_->addLease(lease));
+ EXPECT_TRUE(logs_.empty());
+
+ lmptr_->deleteLease(lease);
+
+ // Make sure that the callback has been invoked.
+ ASSERT_EQ(1, logs_.size());
+
+ // This flag should be false for the Memfile backend and true
+ // for the SQL backends.
+ if (expect_locked) {
+ EXPECT_TRUE(logs_[0].locked);
+ } else {
+ EXPECT_FALSE(logs_[0].locked);
+ }
+ // This flag should be set to true for the Memfile backends.
+ // It should be false for other backends. If the backends do
+ // not provide the MT-safe context, the callbacks must protect
+ // against the concurrent access on their own.
+ if (expect_mt_safe) {
+ EXPECT_TRUE(logs_[0].mt_safe);
+ } else {
+ EXPECT_FALSE(logs_[0].mt_safe);
+ }
+
+ // The lease locks should have been released.
+ EXPECT_FALSE(lmptr_->isLocked(lease));
+}
+
+void
+GenericLeaseMgrTest::testTrackDeleteLease6(bool expect_locked, bool expect_mt_safe) {
+ // Register a callback for all subnets.
+ lmptr_->registerCallback(TrackingLeaseMgr::TRACK_DELETE_LEASE, 0, "flq",
+ std::bind(&GenericLeaseMgrTest::logCallback,
+ this,
+ TrackingLeaseMgr::TRACK_DELETE_LEASE,
+ 0,
+ ph::_1,
+ ph::_2));
+ // Add a lease.
+ Lease6Ptr lease = initializeLease6(straddress6_[1]);
+ EXPECT_TRUE(lmptr_->addLease(lease));
+ EXPECT_TRUE(logs_.empty());
+
+ lmptr_->deleteLease(lease);
+
+ // Make sure that the callback has been invoked.
+ ASSERT_EQ(1, logs_.size());
+
+ // This flag should be false for the Memfile backend and true
+ // for the SQL backends.
+ if (expect_locked) {
+ EXPECT_TRUE(logs_[0].locked);
+ } else {
+ EXPECT_FALSE(logs_[0].locked);
+ }
+ // This flag should be set to true for the Memfile backends.
+ // It should be false for other backends. If the backends do
+ // not provide the MT-safe context, the callbacks must protect
+ // against the concurrent access on their own.
+ if (expect_mt_safe) {
+ EXPECT_TRUE(logs_[0].mt_safe);
+ } else {
+ EXPECT_FALSE(logs_[0].mt_safe);
+ }
+
+ // The lease locks should have been released.
+ EXPECT_FALSE(lmptr_->isLocked(lease));
+}
+
} // namespace test
} // namespace dhcp
} // namespace isc
diff --git a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h
index b7c707df85..82f7e41684 100644
--- a/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h
+++ b/src/lib/dhcpsrv/tests/generic_lease_mgr_unittest.h
@@ -45,6 +45,8 @@ public:
TrackingLeaseMgr::CallbackType type;
SubnetID subnet_id;
LeasePtr lease;
+ bool mt_safe;
+ bool locked;
} Log;
/// @brief Default constructor.
@@ -173,8 +175,10 @@ public:
/// @param type callback type.
/// @param subnet_id subnet identifier.
/// @param lease lease instance.
- void logCallback(const TrackingLeaseMgr::CallbackType type, SubnetID subnet_id,
- const LeasePtr& lease);
+ /// @param mt a boolean flag indicating if the function has been called
+ /// in the thread-safe context.
+ void logCallback(TrackingLeaseMgr::CallbackType type, SubnetID subnet_id,
+ LeasePtr lease, bool mt_safe);
/// @brief Counts log entries.
///
@@ -568,6 +572,60 @@ public:
/// @brief Checks a few v6 lease limit checking scenarios.
void testLeaseLimits6();
+ /// @brief Checks if the backends call the callbacks when an
+ /// IPv4 lease is added.
+ ///
+ /// @param expect_locked a boolean flag indicating if the test should
+ /// expect that the lease is locked before the callback.
+ /// @param expect_mt_safe a boolean flag indicating if the test should
+ /// expect that the callbacks are called in the MT-safe context.
+ void testTrackAddLease4(bool expect_locked, bool expect_mt_safe);
+
+ /// @brief Checks if the backends call the callbacks when an
+ /// IPv6 lease is added.
+ ///
+ /// @param expect_locked a boolean flag indicating if the test should
+ /// expect that the lease is locked before the callback.
+ /// @param expect_mt_safe a boolean flag indicating if the test should
+ /// expect that the callbacks are called in the MT-safe context.
+ void testTrackAddLease6(bool expect_locked, bool expect_mt_safe);
+
+ /// @brief Checks if the backends call the callbacks when an
+ /// IPv4 lease is updated.
+ ///
+ /// @param expect_locked a boolean flag indicating if the test should
+ /// expect that the lease is locked before the callback.
+ /// @param expect_mt_safe a boolean flag indicating if the test should
+ /// expect that the callbacks are called in the MT-safe context.
+ void testTrackUpdateLease4(bool expect_locked, bool expect_mt_safe);
+
+ /// @brief Checks if the backends call the callbacks when an
+ /// IPv6 lease is updated.
+ ///
+ /// @param expect_locked a boolean flag indicating if the test should
+ /// expect that the lease is locked before the callback.
+ /// @param expect_mt_safe a boolean flag indicating if the test should
+ /// expect that the callbacks are called in the MT-safe context.
+ void testTrackUpdateLease6(bool expect_locked, bool expect_mt_safe);
+
+ /// @brief Checks if the backends call the callbacks when an
+ /// IPv4 lease is deleted.
+ ///
+ /// @param expect_locked a boolean flag indicating if the test should
+ /// expect that the lease is locked before the callback.
+ /// @param expect_mt_safe a boolean flag indicating if the test should
+ /// expect that the callbacks are called in the MT-safe context.
+ void testTrackDeleteLease4(bool expect_locked, bool expect_mt_safe);
+
+ /// @brief Checks if the backends call the callbacks when an
+ /// IPv6 lease is deleted.
+ ///
+ /// @param expect_locked a boolean flag indicating if the test should
+ /// expect that the lease is locked before the callback.
+ /// @param expect_mt_safe a boolean flag indicating if the test should
+ /// expect that the callbacks are called in the MT-safe context.
+ void testTrackDeleteLease6(bool expect_locked, bool expect_mt_safe);
+
/// @brief String forms of IPv4 addresses
std::vector<std::string> straddress4_;
@@ -587,7 +645,7 @@ public:
std::vector<Log> logs_;
/// @brief Pointer to the lease manager
- LeaseMgr* lmptr_;
+ TrackingLeaseMgr* lmptr_;
};
class LeaseMgrDbLostCallbackTest : public ::testing::Test {
diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
index fba9dc1568..94d5d4d9d4 100644
--- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
@@ -235,7 +235,7 @@ public:
" lease database backend.\n";
throw;
}
- lmptr_ = &(LeaseMgrFactory::instance());
+ lmptr_ = static_cast<TrackingLeaseMgr*>(&(LeaseMgrFactory::instance()));
}
/// @brief Runs IOService and stops after a specified time.
@@ -2017,7 +2017,7 @@ TEST_F(MemfileLeaseMgrTest, lease4ContainerIndexUpdate) {
// Recreate Memfile_LeaseMgr.
LeaseMgrFactory::destroy();
ASSERT_NO_THROW(LeaseMgrFactory::create(dbaccess));
- lmptr_ = &(LeaseMgrFactory::instance());
+ lmptr_ = static_cast<TrackingLeaseMgr*>(&(LeaseMgrFactory::instance()));
// We will store addresses here, so it will be easier to randomly
// pick a lease.
@@ -2060,7 +2060,7 @@ TEST_F(MemfileLeaseMgrTest, lease4ContainerIndexUpdate) {
// Recreate Memfile_LeaseMgr.
LeaseMgrFactory::destroy();
LeaseMgrFactory::create(dbaccess);
- lmptr_ = &(LeaseMgrFactory::instance());
+ lmptr_ = static_cast<TrackingLeaseMgr*>(&(LeaseMgrFactory::instance()));
});
// Ok, let's check if the leases are really accessible.
@@ -2147,7 +2147,7 @@ TEST_F(MemfileLeaseMgrTest, lease6ContainerIndexUpdate) {
// Recreate Memfile_LeaseMgr.
LeaseMgrFactory::destroy();
ASSERT_NO_THROW(LeaseMgrFactory::create(dbaccess));
- lmptr_ = &(LeaseMgrFactory::instance());
+ lmptr_ = static_cast<TrackingLeaseMgr*>(&(LeaseMgrFactory::instance()));
// We will store addresses here, so it will be easier to randomly
// pick a lease.
@@ -2191,7 +2191,7 @@ TEST_F(MemfileLeaseMgrTest, lease6ContainerIndexUpdate) {
// Recreate Memfile_LeaseMgr.
LeaseMgrFactory::destroy();
LeaseMgrFactory::create(dbaccess);
- lmptr_ = &(LeaseMgrFactory::instance());
+ lmptr_ = static_cast<TrackingLeaseMgr*>(&(LeaseMgrFactory::instance()));
});
// Ok, let's check if the leases are really accessible.
@@ -4237,4 +4237,107 @@ TEST_F(MemfileLeaseMgrTest, buildExtendedInfoTables6rebuild) {
EXPECT_EQ(exp_remote_id, ex_info->id_);
}
+/// @brief Checks if the backends call the callbacks when an
+/// IPv4 lease is added.
+TEST_F(MemfileLeaseMgrTest, trackAddLease4) {
+ startBackend(V4);
+ // Expect that lease is not locked and the MT-safe context.
+ testTrackAddLease4(false, true);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv4 lease is added.
+TEST_F(MemfileLeaseMgrTest, trackAddLease4MultiThreading) {
+ startBackend(V4);
+ MultiThreadingMgr::instance().setMode(true);
+ // Expect that lease is not locked and the MT-safe context.
+ testTrackAddLease4(false, true);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv6 lease is added.
+TEST_F(MemfileLeaseMgrTest, trackAddLease6) {
+ startBackend(V6);
+ // Expect that lease is not locked and the MT-safe context.
+ testTrackAddLease6(false, true);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv6 lease is added.
+TEST_F(MemfileLeaseMgrTest, trackAddLease6MultiThreading) {
+ startBackend(V6);
+ MultiThreadingMgr::instance().setMode(true);
+ // Expect that lease is not locked and the MT-safe context.
+ testTrackAddLease6(false, true);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv4 lease is added.
+TEST_F(MemfileLeaseMgrTest, trackUpdateLease4) {
+ startBackend(V4);
+ // Expect that lease is not locked and the MT-safe context.
+ testTrackUpdateLease4(false, true);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv4 lease is added.
+TEST_F(MemfileLeaseMgrTest, trackUpdateLease4MultiThreading) {
+ startBackend(V4);
+ MultiThreadingMgr::instance().setMode(true);
+ // Expect that lease is not locked and the MT-safe context.
+ testTrackUpdateLease4(false, true);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv6 lease is added.
+TEST_F(MemfileLeaseMgrTest, trackUpdateLease6) {
+ startBackend(V6);
+ // Expect that lease is not locked and the MT-safe context.
+ testTrackUpdateLease6(false, true);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv6 lease is added.
+TEST_F(MemfileLeaseMgrTest, trackUpdateLease6MultiThreading) {
+ startBackend(V6);
+ MultiThreadingMgr::instance().setMode(true);
+ // Expect that lease is not locked and the MT-safe context.
+ testTrackUpdateLease6(false, true);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv4 lease is added.
+TEST_F(MemfileLeaseMgrTest, trackDeleteLease4) {
+ startBackend(V4);
+ // Expect that lease is not locked and the MT-safe context.
+ testTrackDeleteLease4(false, true);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv4 lease is added.
+TEST_F(MemfileLeaseMgrTest, trackDeleteLease4MultiThreading) {
+ startBackend(V4);
+ MultiThreadingMgr::instance().setMode(true);
+ // Expect that lease is not locked and the MT-safe context.
+ testTrackDeleteLease4(false, true);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv6 lease is added.
+TEST_F(MemfileLeaseMgrTest, trackDeleteLease6) {
+ startBackend(V6);
+ // Expect that lease is not locked and the MT-safe context.
+ testTrackDeleteLease6(false, true);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv6 lease is added.
+TEST_F(MemfileLeaseMgrTest, trackDeleteLease6MultiThreading) {
+ startBackend(V6);
+ MultiThreadingMgr::instance().setMode(true);
+ // Expect that lease is not locked and the MT-safe context.
+ testTrackDeleteLease6(false, true);
+}
+
+
} // namespace
diff --git a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
index 548b043a1a..291c72f620 100644
--- a/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/mysql_lease_mgr_unittest.cc
@@ -64,7 +64,7 @@ public:
throw;
}
- lmptr_ = &(LeaseMgrFactory::instance());
+ lmptr_ = static_cast<TrackingLeaseMgr*>(&(LeaseMgrFactory::instance()));
MultiThreadingMgr::instance().setMode(false);
}
@@ -104,7 +104,7 @@ public:
void reopen(Universe) {
LeaseMgrFactory::destroy();
LeaseMgrFactory::create(validMySQLConnectionString());
- lmptr_ = &(LeaseMgrFactory::instance());
+ lmptr_ = static_cast<TrackingLeaseMgr*>(&(LeaseMgrFactory::instance()));
}
};
@@ -1174,4 +1174,106 @@ TEST_F(MySqlLeaseMgrTest, checkLimits6) {
testLeaseLimits6();
}
+/// @brief Checks if the backends call the callbacks when an
+/// IPv4 lease is added.
+TEST_F(MySqlLeaseMgrTest, trackAddLease4) {
+ // It is unnecessary to lock the lease in ST. The backend does not
+ // provide the MT-safe context for the callbacks.
+ testTrackAddLease4(false, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv4 lease is added.
+TEST_F(MySqlLeaseMgrTest, trackAddLease4MultiThreading) {
+ MultiThreadingMgr::instance().setMode(true);
+ // The lease should be locked in the MT mode. The backend does not
+ // provide an MT-safe context.
+ testTrackAddLease4(true, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv6 lease is added.
+TEST_F(MySqlLeaseMgrTest, trackAddLease6) {
+ // It is unnecessary to lock the lease in ST. The backend does not
+ // provide the MT-safe context for the callbacks.
+ testTrackAddLease6(false, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv6 lease is added.
+TEST_F(MySqlLeaseMgrTest, trackAddLease6MultiThreading) {
+ MultiThreadingMgr::instance().setMode(true);
+ // The lease should be locked in the MT mode. The backend does not
+ // provide an MT-safe context.
+ testTrackAddLease6(true, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv4 lease is updated.
+TEST_F(MySqlLeaseMgrTest, trackUpdateLease4) {
+ // It is unnecessary to lock the lease in ST. The backend does not
+ // provide the MT-safe context for the callbacks.
+ testTrackUpdateLease4(false, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv4 lease is updated.
+TEST_F(MySqlLeaseMgrTest, trackUpdateLease4MultiThreading) {
+ MultiThreadingMgr::instance().setMode(true);
+ // The lease should be locked in the MT mode. The backend does not
+ // provide an MT-safe context.
+ testTrackUpdateLease4(true, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv6 lease is updated.
+TEST_F(MySqlLeaseMgrTest, trackUpdateLease6) {
+ // It is unnecessary to lock the lease in ST. The backend does not
+ // provide the MT-safe context for the callbacks.
+ testTrackUpdateLease6(false, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv6 lease is updated.
+TEST_F(MySqlLeaseMgrTest, trackUpdateLease6MultiThreading) {
+ MultiThreadingMgr::instance().setMode(true);
+ // The lease should be locked in the MT mode. The backend does not
+ // provide an MT-safe context.
+ testTrackUpdateLease6(true, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv4 lease is deleted.
+TEST_F(MySqlLeaseMgrTest, trackDeleteLease4) {
+ // It is unnecessary to lock the lease in ST. The backend does not
+ // provide the MT-safe context for the callbacks.
+ testTrackDeleteLease4(false, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv4 lease is deleted.
+TEST_F(MySqlLeaseMgrTest, trackDeleteLease4MultiThreading) {
+ MultiThreadingMgr::instance().setMode(true);
+ // The lease should be locked in the MT mode. The backend does not
+ // provide an MT-safe context.
+ testTrackDeleteLease4(true, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv6 lease is deleted.
+TEST_F(MySqlLeaseMgrTest, trackDeleteLease6) {
+ // It is unnecessary to lock the lease in ST. The backend does not
+ // provide the MT-safe context for the callbacks.
+ testTrackDeleteLease6(false, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv6 lease is deleted.
+TEST_F(MySqlLeaseMgrTest, trackDeleteLease6MultiThreading) {
+ MultiThreadingMgr::instance().setMode(true);
+ // The lease should be locked in the MT mode. The backend does not
+ // provide an MT-safe context.
+ testTrackDeleteLease6(true, false);
+}
+
} // namespace
diff --git a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc
index 90b06ca706..42d47bf03c 100644
--- a/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/pgsql_lease_mgr_unittest.cc
@@ -64,7 +64,7 @@ public:
throw;
}
- lmptr_ = &(LeaseMgrFactory::instance());
+ lmptr_ = static_cast<TrackingLeaseMgr*>(&(LeaseMgrFactory::instance()));
MultiThreadingMgr::instance().setMode(false);
}
@@ -104,7 +104,7 @@ public:
void reopen(Universe) {
LeaseMgrFactory::destroy();
LeaseMgrFactory::create(validPgSQLConnectionString());
- lmptr_ = &(LeaseMgrFactory::instance());
+ lmptr_ = static_cast<TrackingLeaseMgr*>(&(LeaseMgrFactory::instance()));
}
};
@@ -1163,4 +1163,106 @@ TEST_F(PgSqlLeaseMgrTest, checkLimits6) {
testLeaseLimits6();
}
+/// @brief Checks if the backends call the callbacks when an
+/// IPv4 lease is added.
+TEST_F(PgSqlLeaseMgrTest, trackAddLease4) {
+ // It is unnecessary to lock the lease in ST. The backend does not
+ // provide the MT-safe context for the callbacks.
+ testTrackAddLease4(false, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv4 lease is added.
+TEST_F(PgSqlLeaseMgrTest, trackAddLease4MultiThreading) {
+ MultiThreadingMgr::instance().setMode(true);
+ // The lease should be locked in the MT mode. The backend does not
+ // provide an MT-safe context.
+ testTrackAddLease4(true, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv6 lease is added.
+TEST_F(PgSqlLeaseMgrTest, trackAddLease6) {
+ // It is unnecessary to lock the lease in ST. The backend does not
+ // provide the MT-safe context for the callbacks.
+ testTrackAddLease6(false, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv6 lease is added.
+TEST_F(PgSqlLeaseMgrTest, trackAddLease6MultiThreading) {
+ MultiThreadingMgr::instance().setMode(true);
+ // The lease should be locked in the MT mode. The backend does not
+ // provide an MT-safe context.
+ testTrackAddLease6(true, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv4 lease is updated.
+TEST_F(PgSqlLeaseMgrTest, trackUpdateLease4) {
+ // It is unnecessary to lock the lease in ST. The backend does not
+ // provide the MT-safe context for the callbacks.
+ testTrackUpdateLease4(false, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv4 lease is updated.
+TEST_F(PgSqlLeaseMgrTest, trackUpdateLease4MultiThreading) {
+ MultiThreadingMgr::instance().setMode(true);
+ // The lease should be locked in the MT mode. The backend does not
+ // provide an MT-safe context.
+ testTrackUpdateLease4(true, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv6 lease is updated.
+TEST_F(PgSqlLeaseMgrTest, trackUpdateLease6) {
+ // It is unnecessary to lock the lease in ST. The backend does not
+ // provide the MT-safe context for the callbacks.
+ testTrackUpdateLease6(false, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv6 lease is updated.
+TEST_F(PgSqlLeaseMgrTest, trackUpdateLease6MultiThreading) {
+ MultiThreadingMgr::instance().setMode(true);
+ // The lease should be locked in the MT mode. The backend does not
+ // provide an MT-safe context.
+ testTrackUpdateLease6(true, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv4 lease is deleted.
+TEST_F(PgSqlLeaseMgrTest, trackDeleteLease4) {
+ // It is unnecessary to lock the lease in ST. The backend does not
+ // provide the MT-safe context for the callbacks.
+ testTrackDeleteLease4(false, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv4 lease is deleted.
+TEST_F(PgSqlLeaseMgrTest, trackDeleteLease4MultiThreading) {
+ MultiThreadingMgr::instance().setMode(true);
+ // The lease should be locked in the MT mode. The backend does not
+ // provide an MT-safe context.
+ testTrackDeleteLease4(true, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv6 lease is deleted.
+TEST_F(PgSqlLeaseMgrTest, trackDeleteLease6) {
+ // It is unnecessary to lock the lease in ST. The backend does not
+ // provide the MT-safe context for the callbacks.
+ testTrackDeleteLease6(false, false);
+}
+
+/// @brief Checks if the backends call the callbacks when an
+/// IPv6 lease is deleted.
+TEST_F(PgSqlLeaseMgrTest, trackDeleteLease6MultiThreading) {
+ MultiThreadingMgr::instance().setMode(true);
+ // The lease should be locked in the MT mode. The backend does not
+ // provide an MT-safe context.
+ testTrackDeleteLease6(true, false);
+}
+
} // namespace
diff --git a/src/lib/dhcpsrv/tests/tracking_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/tracking_lease_mgr_unittest.cc
index 64d284d2ea..6b71fffb21 100644
--- a/src/lib/dhcpsrv/tests/tracking_lease_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/tracking_lease_mgr_unittest.cc
@@ -61,15 +61,20 @@ TEST_F(TrackingLeaseMgrTest, tryLock) {
// An attempt to lock an already locked lease should fail.
EXPECT_TRUE(mgr.tryLock(initializeLease<Lease4>(1, "192.0.2.1")));
EXPECT_FALSE(mgr.tryLock(initializeLease<Lease4>(1, "192.0.2.1")));
+ EXPECT_TRUE(mgr.isLocked(initializeLease<Lease4>(1, "192.0.2.1")));
// We can lock another lease but we cannot lock an already locked one.
EXPECT_TRUE(mgr.tryLock(initializeLease<Lease4>(1, "192.0.2.2")));
EXPECT_FALSE(mgr.tryLock(initializeLease<Lease4>(1, "192.0.2.1")));
EXPECT_FALSE(mgr.tryLock(initializeLease<Lease4>(2, "192.0.2.2")));
+ EXPECT_TRUE(mgr.isLocked(initializeLease<Lease4>(1, "192.0.1.2")));
+ EXPECT_TRUE(mgr.isLocked(initializeLease<Lease4>(2, "192.0.2.2")));
// If we unlock the lease, it can be locked again. However, unlocking
// the lease should not affect other locks.
mgr.unlock(initializeLease<Lease4>(1, "192.0.2.1"));
+ EXPECT_FALSE(mgr.isLocked(initializeLease<Lease4>(1, "192.0.2.1")));
+ EXPECT_TRUE(mgr.isLocked(initializeLease<Lease4>(2, "192.0.2.2")));
EXPECT_FALSE(mgr.tryLock(initializeLease<Lease4>(2, "192.0.2.2")));
EXPECT_TRUE(mgr.tryLock(initializeLease<Lease4>(1, "192.0.2.1")));
}
@@ -85,35 +90,35 @@ TEST_F(TrackingLeaseMgrTest, registerCallbacks) {
this,
TrackingLeaseMgr::TRACK_ADD_LEASE,
0,
- _1)));
+ _1, _2)));
// Callback for lease add and subnet id 1.
EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, 1, "flq",
std::bind(&TrackingLeaseMgrTest::logCallback,
this,
TrackingLeaseMgr::TRACK_ADD_LEASE,
1,
- _1)));
+ _1, _2)));
// Callback for lease add and subnet id 2.
EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, 2, "flq",
std::bind(&TrackingLeaseMgrTest::logCallback,
this,
TrackingLeaseMgr::TRACK_ADD_LEASE,
1,
- _1)));
+ _1, _2)));
// Callback for lease update and subnet id 0.
EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, 0, "flq",
std::bind(&TrackingLeaseMgrTest::logCallback,
this,
TrackingLeaseMgr::TRACK_UPDATE_LEASE,
0,
- _1)));
+ _1, _2)));
// Callback for lease delete and subnet id 0.
EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_DELETE_LEASE, 0, "flq",
std::bind(&TrackingLeaseMgrTest::logCallback,
this,
TrackingLeaseMgr::TRACK_DELETE_LEASE,
1,
- _1)));
+ _1, _2)));
// This call should trigger the lease add callbacks for subnet id 0 and 1.
EXPECT_NO_THROW(mgr.trackAddLease(initializeLease<Lease4>(1, "192.0.2.1"), false));
@@ -140,7 +145,7 @@ TEST_F(TrackingLeaseMgrTest, registerCallbacksConflicts) {
this,
TrackingLeaseMgr::TRACK_ADD_LEASE,
0,
- _1)));
+ _1, _2)));
// Another attempt should fail.
EXPECT_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, 0, "flq",
@@ -148,7 +153,7 @@ TEST_F(TrackingLeaseMgrTest, registerCallbacksConflicts) {
this,
TrackingLeaseMgr::TRACK_ADD_LEASE,
0,
- _1)),
+ _1, _2)),
InvalidOperation);
// It should succeed for a different owner.
@@ -157,7 +162,7 @@ TEST_F(TrackingLeaseMgrTest, registerCallbacksConflicts) {
this,
TrackingLeaseMgr::TRACK_ADD_LEASE,
0,
- _1)));
+ _1, _2)));
// It should also succeed for a different subnet id.
EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, 5, "qlf",
@@ -165,7 +170,7 @@ TEST_F(TrackingLeaseMgrTest, registerCallbacksConflicts) {
this,
TrackingLeaseMgr::TRACK_ADD_LEASE,
5,
- _1)));
+ _1, _2)));
// But, another attempt for the subnet id should fail.
EXPECT_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, 5, "qlf",
@@ -173,7 +178,7 @@ TEST_F(TrackingLeaseMgrTest, registerCallbacksConflicts) {
this,
TrackingLeaseMgr::TRACK_ADD_LEASE,
5,
- _1)),
+ _1, _2)),
InvalidOperation);
}
@@ -187,19 +192,19 @@ TEST_F(TrackingLeaseMgrTest, trackUpdateLease) {
this,
TrackingLeaseMgr::TRACK_ADD_LEASE,
0,
- _1)));
+ _1, _2)));
EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, 0, "flq",
std::bind(&TrackingLeaseMgrTest::logCallback,
this,
TrackingLeaseMgr::TRACK_UPDATE_LEASE,
0,
- _1)));
+ _1, _2)));
EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_DELETE_LEASE, 0, "flq",
std::bind(&TrackingLeaseMgrTest::logCallback,
this,
TrackingLeaseMgr::TRACK_DELETE_LEASE,
0,
- _1)));
+ _1, _2)));
EXPECT_NO_THROW(mgr.trackUpdateLease(initializeLease<Lease4>(1, "192.0.2.1"), false));
EXPECT_EQ(1, logs_.size());
EXPECT_EQ(1, countLogs(TrackingLeaseMgr::TRACK_UPDATE_LEASE, 0));
@@ -215,19 +220,19 @@ TEST_F(TrackingLeaseMgrTest, trackDeleteLease) {
this,
TrackingLeaseMgr::TRACK_ADD_LEASE,
0,
- _1)));
+ _1, _2)));
EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, 0, "flq",
std::bind(&TrackingLeaseMgrTest::logCallback,
this,
TrackingLeaseMgr::TRACK_UPDATE_LEASE,
0,
- _1)));
+ _1, _2)));
EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_DELETE_LEASE, 0, "flq",
std::bind(&TrackingLeaseMgrTest::logCallback,
this,
TrackingLeaseMgr::TRACK_DELETE_LEASE,
0,
- _1)));
+ _1, _2)));
EXPECT_NO_THROW(mgr.trackDeleteLease(initializeLease<Lease4>(1, "192.0.2.1"), false));
EXPECT_EQ(1, logs_.size());
EXPECT_EQ(1, countLogs(TrackingLeaseMgr::TRACK_DELETE_LEASE, 0));
@@ -244,43 +249,43 @@ TEST_F(TrackingLeaseMgrTest, unregisterCallbacksBySubnetID) {
this,
TrackingLeaseMgr::TRACK_ADD_LEASE,
0,
- _1)));
+ _1, _2)));
EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, 1, "flq",
std::bind(&TrackingLeaseMgrTest::logCallback,
this,
TrackingLeaseMgr::TRACK_ADD_LEASE,
1,
- _1)));
+ _1, _2)));
EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_ADD_LEASE, 2, "flq",
std::bind(&TrackingLeaseMgrTest::logCallback,
this,
TrackingLeaseMgr::TRACK_ADD_LEASE,
2,
- _1)));
+ _1, _2)));
EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, 1, "flq",
std::bind(&TrackingLeaseMgrTest::logCallback,
this,
TrackingLeaseMgr::TRACK_UPDATE_LEASE,
1,
- _1)));
+ _1, _2)));
EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, 2, "flq",
std::bind(&TrackingLeaseMgrTest::logCallback,
this,
TrackingLeaseMgr::TRACK_UPDATE_LEASE,
2,
- _1)));
+ _1, _2)));
EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_DELETE_LEASE, 1, "flq",
std::bind(&TrackingLeaseMgrTest::logCallback,
this,
TrackingLeaseMgr::TRACK_DELETE_LEASE,
1,
- _1)));
+ _1, _2)));
EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_DELETE_LEASE, 2, "flq",
std::bind(&TrackingLeaseMgrTest::logCallback,
this,
TrackingLeaseMgr::TRACK_DELETE_LEASE,
2,
- _1)));
+ _1, _2)));
// Unregister the callbacks for subnet id 1.
EXPECT_NO_THROW(mgr.unregisterCallbacks(SubnetID(1)));
@@ -317,13 +322,13 @@ TEST_F(TrackingLeaseMgrTest, unregisterAllCallbacks) {
this,
TrackingLeaseMgr::TRACK_ADD_LEASE,
0,
- _1)));
+ _1, _2)));
EXPECT_NO_THROW(mgr.registerCallback(TrackingLeaseMgr::TRACK_UPDATE_LEASE, 0, "flq",
std::bind(&TrackingLeaseMgrTest::logCallback,
this,
TrackingLeaseMgr::TRACK_UPDATE_LEASE,
0,
- _1)));
+ _1, _2)));
// Make sure they have been registered.
EXPECT_TRUE(mgr.hasCallbacks());
@@ -343,7 +348,7 @@ TEST_F(TrackingLeaseMgrTest, hasCallbacks) {
this,
TrackingLeaseMgr::TRACK_ADD_LEASE,
0,
- _1)));
+ _1, _2)));
EXPECT_TRUE(mgr.hasCallbacks());
}