2
0
mirror of https://gitlab.isc.org/isc-projects/kea synced 2025-08-29 21:18:02 +00:00

[#1878] fixed unittests

This commit is contained in:
Razvan Becheriu 2021-06-08 13:38:58 +03:00
parent ef6f0a4ddf
commit fbb389aea2
4 changed files with 25 additions and 6 deletions

View File

@ -32,9 +32,8 @@ RunScriptImpl::configure(LibraryHandle& handle) {
if (name->getType() != Element::string) { if (name->getType() != Element::string) {
isc_throw(InvalidParameter, "The 'name' parameter must be a string"); isc_throw(InvalidParameter, "The 'name' parameter must be a string");
} }
IOServicePtr io_service(new asiolink::IOService());
try { try {
ProcessSpawn process(io_service, name->stringValue()); ProcessSpawn process(IOServicePtr(), name->stringValue());
} catch (const isc::Exception& ex) { } catch (const isc::Exception& ex) {
isc_throw(InvalidParameter, "Invalid 'name' parameter: " << ex.what()); isc_throw(InvalidParameter, "Invalid 'name' parameter: " << ex.what());
} }
@ -50,7 +49,7 @@ RunScriptImpl::configure(LibraryHandle& handle) {
void void
RunScriptImpl::runScript(const ProcessArgs& args, const ProcessEnvVars& vars) { RunScriptImpl::runScript(const ProcessArgs& args, const ProcessEnvVars& vars) {
ProcessSpawn process(io_service_, name_, args, vars); ProcessSpawn process(getIOService(), name_, args, vars);
process.spawn(true); process.spawn(true);
} }

View File

@ -37,6 +37,13 @@ public:
io_service_ = io_service; io_service_ = io_service;
} }
/// @brief Gets IO service to be used by the @ref ProcessSpawn instance.
///
/// @return The IOService object, used for all ASIO operations.
static isc::asiolink::IOServicePtr getIOService() {
return (io_service_);
}
/// @brief Extract boolean data and append to environment. /// @brief Extract boolean data and append to environment.
/// ///
/// @param value The value to be exported to target script environment. /// @param value The value to be exported to target script environment.

View File

@ -34,6 +34,12 @@ public:
/// @brief IOService instance to process IO. /// @brief IOService instance to process IO.
asiolink::IOServicePtr io_service_; asiolink::IOServicePtr io_service_;
/// @brief Single instance of IOService.
static asiolink::IOServicePtr getIOService() {
static asiolink::IOServicePtr io_service(new asiolink::IOService());
return (io_service);
}
/// @brief Failsafe timer to ensure test(s) do not hang. /// @brief Failsafe timer to ensure test(s) do not hang.
isc::asiolink::IntervalTimer test_timer_; isc::asiolink::IntervalTimer test_timer_;
@ -48,7 +54,7 @@ public:
/// @brief Constructor. /// @brief Constructor.
ProcessSpawnTest() : ProcessSpawnTest() :
io_service_(new asiolink::IOService()), test_timer_(*io_service_), io_service_(getIOService()), test_timer_(*io_service_),
test_time_ms_(0), io_signal_set_(), processed_signals_() { test_time_ms_(0), io_signal_set_(), processed_signals_() {
io_signal_set_.reset(new IOSignalSet(io_service_, io_signal_set_.reset(new IOSignalSet(io_service_,
@ -58,7 +64,9 @@ public:
} }
/// @brief Destructor. /// @brief Destructor.
~ProcessSpawnTest() {} ~ProcessSpawnTest() {
io_signal_set_->remove(SIGCHLD);
}
/// @brief Method used as the IOSignalSet handler. /// @brief Method used as the IOSignalSet handler.
/// ///

View File

@ -104,7 +104,7 @@ public:
MemfileLeaseMgrTest() : MemfileLeaseMgrTest() :
io4_(getLeaseFilePath("leasefile4_0.csv")), io4_(getLeaseFilePath("leasefile4_0.csv")),
io6_(getLeaseFilePath("leasefile6_0.csv")), io6_(getLeaseFilePath("leasefile6_0.csv")),
io_service_(new IOService()), io_service_(getIOService()),
timer_mgr_(TimerMgr::instance()) { timer_mgr_(TimerMgr::instance()) {
timer_mgr_->setIOService(io_service_); timer_mgr_->setIOService(io_service_);
@ -253,6 +253,11 @@ public:
return (!elapsed); return (!elapsed);
} }
/// @brief Single instance of IOService.
static asiolink::IOServicePtr getIOService() {
static asiolink::IOServicePtr io_service(new asiolink::IOService());
return (io_service);
}
/// @brief Generates a DHCPv4 lease with random content. /// @brief Generates a DHCPv4 lease with random content.
/// ///