void setTestTime(const uint32_t ms) {
IntervalTimer timer(*io_service_);
timer.setup([this]() {
- io_service_->stop();
+ io_service_->stop();
}, ms, IntervalTimer::ONE_SHOT);
io_service_->run();
io_service_->get_io_service().reset();
}
+ /// @brief Waits for the specified process to finish.
+ ///
+ /// @param process An object which started the process.
+ /// @param timeout Timeout in seconds.
+ ///
+ /// @return true if the process ended, false otherwise
+ bool waitForProcess(const Memfile_LeaseMgr& lease_mgr,
+ const uint8_t timeout) {
+ const uint32_t iterations_max = timeout * 1000;
+ IntervalTimer fast_path_timer(*io_service_);
+ IntervalTimer timer(*io_service_);
+ bool elapsed = false;
+ timer.setup([&]() {
+ io_service_->stop();
+ elapsed = true;
+ }, iterations_max, IntervalTimer::ONE_SHOT);
+
+ fast_path_timer.setup([&]() {
+ if (!lease_mgr.isLFCRunning()) {
+ io_service_->stop();
+ }
+ }, 1, IntervalTimer::REPEATING);
+
+ io_service_->run();
+ io_service_->get_io_service().reset();
+ return (!elapsed);
+ }
+
+
/// @brief Generates a DHCPv4 lease with random content.
///
/// The following lease parameters are randomly generated:
EXPECT_EQ(new_file_contents, current_file.readFile());
// Wait for the LFC process to complete.
- setTestTime(500);
+ ASSERT_TRUE(waitForProcess(*lease_mgr, 2));
// And make sure it has returned an exit status of 0.
EXPECT_EQ(0, lease_mgr->getLFCExitStatus())
EXPECT_EQ(new_file_contents, current_file.readFile());
// Wait for the LFC process to complete.
- setTestTime(500);
+ ASSERT_TRUE(waitForProcess(*lease_mgr, 2));
// And make sure it has returned an exit status of 0.
EXPECT_EQ(0, lease_mgr->getLFCExitStatus())
ASSERT_NO_THROW(lease_mgr->lfcCallback());
// Wait for the LFC process to complete.
- setTestTime(100);
+ ASSERT_TRUE(waitForProcess(*lease_mgr, 2));
// And make sure it has returned an error.
EXPECT_EQ(EXIT_FAILURE, lease_mgr->getLFCExitStatus())
EXPECT_EQ(current_file_contents, current_file.readFile());
// Wait for the LFC process to complete.
- setTestTime(100);
+ ASSERT_TRUE(waitForProcess(*lease_mgr, 5));
// And make sure it has returned an exit status of 0.
EXPECT_EQ(0, lease_mgr->getLFCExitStatus())
EXPECT_EQ(current_file_contents, current_file.readFile());
// Wait for the LFC process to complete.
- setTestTime(100);
+ ASSERT_TRUE(waitForProcess(*lease_mgr, 5));
// And make sure it has returned an exit status of 0.
EXPECT_EQ(0, lease_mgr->getLFCExitStatus())
// Wait for the LFC process to complete and
// make sure it has returned an exit status of 0.
- setTestTime(100);
+ ASSERT_TRUE(waitForProcess(*lease_mgr, 2));
ASSERT_EQ(0, lease_mgr->getLFCExitStatus())
<< "Executing the LFC process failed: make sure that"
// Wait for the LFC process to complete and
// make sure it has returned an exit status of 0.
- setTestTime(100);
+ ASSERT_TRUE(waitForProcess(*lease_mgr, 2));
ASSERT_EQ(0, lease_mgr->getLFCExitStatus())
<< "Executing the LFC process failed: make sure that"