summaryrefslogtreecommitdiffstats
path: root/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc')
-rw-r--r--src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc67
1 files changed, 39 insertions, 28 deletions
diff --git a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
index f52f2c1bd3..8471ff7ed8 100644
--- a/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
+++ b/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
@@ -1,4 +1,4 @@
-// Copyright (C) 2012-2016 Internet Systems Consortium, Inc. ("ISC")
+// Copyright (C) 2012-2017 Internet Systems Consortium, Inc. ("ISC")
//
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
@@ -6,6 +6,7 @@
#include <config.h>
#include <asiolink/asio_wrapper.h>
+#include <asiolink/interval_timer.h>
#include <asiolink/io_address.h>
#include <dhcp/duid.h>
#include <dhcp/iface_mgr.h>
@@ -102,8 +103,11 @@ public:
MemfileLeaseMgrTest() :
io4_(getLeaseFilePath("leasefile4_0.csv")),
io6_(getLeaseFilePath("leasefile6_0.csv")),
+ io_service_(new IOService()),
timer_mgr_(TimerMgr::instance()) {
+ timer_mgr_->setIOService(io_service_);
+
std::ostringstream s;
s << KEA_LFC_BUILD_DIR << "/kea-lfc";
setenv("KEA_LFC_EXECUTABLE", s.str().c_str(), 1);
@@ -130,7 +134,6 @@ public:
/// destroys lease manager backend.
virtual ~MemfileLeaseMgrTest() {
// Stop TimerMgr worker thread if it is running.
- timer_mgr_->stopThread();
// Make sure there are no timers registered.
timer_mgr_->unregisterTimers();
LeaseMgrFactory::destroy();
@@ -143,7 +146,7 @@ public:
/// @brief Remove files being products of Lease File Cleanup.
///
/// @param base_name Path to the lease file name. This file is removed
- /// and all files which names are crated from this name (having specific
+ /// and all files which names are created from this name (having specific
/// suffixes used by Lease File Cleanup mechanism).
void removeFiles(const std::string& base_name) const {
// Generate suffixes and append them to the base name. The
@@ -207,12 +210,13 @@ public:
///
/// @param ms Duration in milliseconds.
void setTestTime(const uint32_t ms) {
- // Measure test time and exit if timeout hit.
- Stopwatch stopwatch;
- while (stopwatch.getTotalMilliseconds() < ms) {
- // Block for one 1 millisecond.
- IfaceMgr::instance().receive6(0, 1000);
- }
+ IntervalTimer timer(*io_service_);
+ timer.setup([this]() {
+ io_service_->stop();
+ }, ms, IntervalTimer::ONE_SHOT);
+
+ io_service_->run();
+ io_service_->get_io_service().reset();
}
/// @brief Waits for the specified process to finish.
@@ -344,6 +348,9 @@ public:
/// @brief Object providing access to v6 lease IO.
LeaseFileIO io6_;
+ /// @brief Pointer to the IO service used by the tests.
+ IOServicePtr io_service_;
+
/// @brief Pointer to the instance of the @c TimerMgr.
TimerMgrPtr timer_mgr_;
};
@@ -375,6 +382,12 @@ TEST_F(MemfileLeaseMgrTest, constructor) {
EXPECT_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)), isc::BadValue);
}
+// Checks if there is no lease manager NoLeaseManager is thrown.
+TEST_F(MemfileLeaseMgrTest, noLeaseManager) {
+ LeaseMgrFactory::destroy();
+ EXPECT_THROW(LeaseMgrFactory::instance(), NoLeaseManager);
+}
+
// Checks if the getType() and getName() methods both return "memfile".
TEST_F(MemfileLeaseMgrTest, getTypeAndName) {
startBackend(V4);
@@ -403,7 +416,7 @@ TEST_F(MemfileLeaseMgrTest, getLeaseFilePath) {
EXPECT_TRUE(lease_mgr->getLeaseFilePath(Memfile_LeaseMgr::V6).empty());
}
-// Check if the persitLeases correctly checks that leases should not be written
+// Check if the persistLeases correctly checks that leases should not be written
// to disk when disabled through configuration.
TEST_F(MemfileLeaseMgrTest, persistLeases) {
// Initialize IO objects, so as the test csv files get removed after the
@@ -447,15 +460,9 @@ TEST_F(MemfileLeaseMgrTest, lfcTimer) {
boost::scoped_ptr<LFCMemfileLeaseMgr>
lease_mgr(new LFCMemfileLeaseMgr(pmap));
- // Start worker thread to execute LFC periodically.
- ASSERT_NO_THROW(timer_mgr_->startThread());
-
// Run the test for at most 2.9 seconds.
setTestTime(2900);
- // Stop worker thread.
- ASSERT_NO_THROW(timer_mgr_->stopThread());
-
// Within 2.9 we should record two LFC executions.
EXPECT_EQ(2, lease_mgr->getLFCCount());
}
@@ -474,17 +481,9 @@ TEST_F(MemfileLeaseMgrTest, lfcTimerDisabled) {
boost::scoped_ptr<LFCMemfileLeaseMgr>
lease_mgr(new LFCMemfileLeaseMgr(pmap));
- // Start worker thread to execute LFC periodically.
- ASSERT_NO_THROW(timer_mgr_->startThread());
-
// Run the test for at most 1.9 seconds.
setTestTime(1900);
- // Stop worker thread to make sure it is not running when lease
- // manager is destroyed. The lease manager will be unable to
- // unregster timer when the thread is active.
- ASSERT_NO_THROW(timer_mgr_->stopThread());
-
// There should be no LFC execution recorded.
EXPECT_EQ(0, lease_mgr->getLFCCount());
}
@@ -1230,7 +1229,7 @@ TEST_F(MemfileLeaseMgrTest, load4LFCInProgress) {
ASSERT_THROW(lease_mgr.reset(new NakedMemfileLeaseMgr(pmap)),
DbOpenError);
- // Remove the pid file, and retry. The bakckend should be created.
+ // Remove the pid file, and retry. The backend should be created.
pid_file.deleteFile();
ASSERT_NO_THROW(lease_mgr.reset(new NakedMemfileLeaseMgr(pmap)));
}
@@ -1480,7 +1479,7 @@ TEST_F(MemfileLeaseMgrTest, load6LFCInProgress) {
ASSERT_THROW(lease_mgr.reset(new NakedMemfileLeaseMgr(pmap)),
DbOpenError);
- // Remove the pid file, and retry. The bakckend should be created.
+ // Remove the pid file, and retry. The backend should be created.
pid_file.deleteFile();
ASSERT_NO_THROW(lease_mgr.reset(new NakedMemfileLeaseMgr(pmap)));
}
@@ -1647,7 +1646,7 @@ TEST_F(MemfileLeaseMgrTest, lease4ContainerIndexUpdate) {
// pick a lease.
std::vector<IOAddress> lease_addresses;
- // Generarate random leases. We remember their addresses in
+ // Generate random leases. We remember their addresses in
// lease_addresses.
for (uint32_t i = 0; i < leases_cnt; ++i) {
Lease4Ptr lease = initiateRandomLease4(addr);
@@ -1786,7 +1785,7 @@ TEST_F(MemfileLeaseMgrTest, lease6ContainerIndexUpdate) {
// pick a lease.
std::vector<IOAddress> lease_addresses;
- // Generarate random leases. We remember their addresses in
+ // Generate random leases. We remember their addresses in
// lease_addresses.
for (uint32_t i = 0; i < leases_cnt; ++i) {
Lease6Ptr lease = initiateRandomLease6(addr);
@@ -1895,4 +1894,16 @@ TEST_F(MemfileLeaseMgrTest, recountLeaseStats6) {
testRecountLeaseStats6();
}
+// Tests that leases from specific subnet can be removed.
+TEST_F(MemfileLeaseMgrTest, wipeLeases4) {
+ startBackend(V4);
+ testWipeLeases4();
+}
+
+// Tests that leases from specific subnet can be removed.
+TEST_F(MemfileLeaseMgrTest, wipeLeases6) {
+ startBackend(V6);
+ testWipeLeases6();
+}
+
}; // end of anonymous namespace