[#4220] Added basic UT

/src/lib/dhcpsrv/memfile_lease_mgr.h
    util::ReconnectCtlPtr reconnectCtl() - getter for testing only

/src/lib/dhcpsrv/tests/memfile_lease_mgr_unittest.cc
    TEST_F(MemfileLeaseMgrTest, constructorReconnectParams) - new test

src/lib/util/reconnect_ctl.h
    ReconnectCtl::OnFailAction onFailAction() - new getter
This commit is contained in:
Thomas Markwalder
2025-12-03 16:00:58 -05:00
parent 3d3b005171
commit 06e920b3ea
3 changed files with 81 additions and 0 deletions

View File

@@ -1659,6 +1659,8 @@ private:
/// @brief Post a call to the appropriate main thread callback when memfile
/// access is lost (e.g. disk full).
/// Note this should only be called within a thread-safe context
/// (i.e. inside *Internal functions).
void handleDbLost();
public:
@@ -1670,6 +1672,12 @@ public:
/// @return The Memfile Lease Manager.
static TrackingLeaseMgrPtr
factory(const isc::db::DatabaseConnection::ParameterMap& parameters);
/// @brief Returns the connection's ReconnectCtl object.
/// This is intended for testing purposes only.
util::ReconnectCtlPtr reconnectCtl() {
return (conn_.reconnectCtl());
}
};
/// @brief Initialization structure used to register and deregister Memfile Lease Mgr.

View File

@@ -476,6 +476,74 @@ TEST_F(MemfileLeaseMgrTest, constructor) {
EXPECT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)));
}
TEST_F(MemfileLeaseMgrTest, constructorReconnectParams) {
DatabaseConnection::ParameterMap pmap;
pmap["universe"] = "6";
pmap["persist"] = "false";
boost::scoped_ptr<Memfile_LeaseMgr> lease_mgr;
ASSERT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)));
auto recon = lease_mgr->reconnectCtl();
ASSERT_TRUE(recon);
EXPECT_EQ(recon->onFailAction(), OnFailAction::STOP_RETRY_EXIT);
EXPECT_EQ(recon->maxRetries(), 0);
EXPECT_EQ(recon->retryInterval(), 0);
pmap["on-fail"] = "stop-retry-exit";
ASSERT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)));
recon = lease_mgr->reconnectCtl();
ASSERT_TRUE(recon);
EXPECT_EQ(recon->onFailAction(), OnFailAction::STOP_RETRY_EXIT);
EXPECT_EQ(recon->maxRetries(), 0);
EXPECT_EQ(recon->retryInterval(), 0);
pmap["on-fail"] = "serve-retry-exit";
ASSERT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)));
recon = lease_mgr->reconnectCtl();
ASSERT_TRUE(recon);
EXPECT_EQ(recon->onFailAction(), OnFailAction::SERVE_RETRY_EXIT);
EXPECT_EQ(recon->maxRetries(), 0);
EXPECT_EQ(recon->retryInterval(), 0);
pmap["on-fail"] = "serve-retry-continue";
ASSERT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)));
recon = lease_mgr->reconnectCtl();
ASSERT_TRUE(recon);
EXPECT_EQ(recon->onFailAction(), OnFailAction::SERVE_RETRY_CONTINUE);
EXPECT_EQ(recon->maxRetries(), 0);
EXPECT_EQ(recon->retryInterval(), 0);
pmap["max-reconnect-tries"] = "5";
EXPECT_THROW_MSG(lease_mgr.reset(new Memfile_LeaseMgr(pmap)), BadValue,
"'max-reconnect-tries' values greater than zero"
" are not supported by memfile");
pmap["max-reconnect-tries"] = "0";
ASSERT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)));
recon = lease_mgr->reconnectCtl();
ASSERT_TRUE(recon);
EXPECT_EQ(recon->maxRetries(), 0);
EXPECT_EQ(recon->retryInterval(), 0);
pmap["reconnect-wait-time"] = "5";
EXPECT_THROW_MSG(lease_mgr.reset(new Memfile_LeaseMgr(pmap)), BadValue,
"'reconnect-wait-time' values greater than zero"
" are not supported by memfile");
pmap["reconnect-wait-time"] = "0";
ASSERT_NO_THROW(lease_mgr.reset(new Memfile_LeaseMgr(pmap)));
recon = lease_mgr->reconnectCtl();
ASSERT_TRUE(recon);
EXPECT_EQ(recon->maxRetries(), 0);
EXPECT_EQ(recon->retryInterval(), 0);
}
/// @brief Verifies that the supported path is the enforced.
TEST_F(MemfileLeaseMgrTest, defaultDataDir) {
ASSERT_TRUE(data_dir_env_var_.getValue().empty());

View File

@@ -108,6 +108,11 @@ public:
(action_ == OnFailAction::SERVE_RETRY_EXIT));
}
/// @brief Returns the on fail action value.
OnFailAction onFailAction() const {
return (action_);
}
/// @brief Convert action to string.
///
/// @param action The action type to be converted to text.