summaryrefslogtreecommitdiffstats
path: root/src/lib/asiolink/tests
diff options
context:
space:
mode:
authorAndrei Pavel <andrei@isc.org>2024-02-23 19:01:00 +0100
committerAndrei Pavel <andrei@isc.org>2024-02-23 19:01:00 +0100
commit6bfbdab033eed9a900f49d56d7da866df8e5593c (patch)
tree4a6da7612e4d223847ebce5aab23df3aa39d8d95 /src/lib/asiolink/tests
parent[#3141] addressed review comments (diff)
downloadkea-6bfbdab033eed9a900f49d56d7da866df8e5593c.tar.xz
kea-6bfbdab033eed9a900f49d56d7da866df8e5593c.zip
[#3025] fix ProcessSpawn on BSD
- Always break after collecting exit status. Previously it broke the loop always on failure of waitpid which does happen after calling it subsequently, but there is no reason to wait until then. - When waitpid returns -1 in sync mode, throw exception, except for EINTR which happens on signals (usually one time) prior to the child process exiting if sigaction is called without SA_RESTART which is the default on some systems. - Only initialize the global IO signal set on the IO service in async mode. It makes no sense to do it in sync mode because there is no IO service. - Swap pid and wpid names to conform to names in `man wait` on BSD. - Add FAIL() on timer expiration. - Don't call runOne() the third time in unit tests because it waits for the timer to expire.
Diffstat (limited to 'src/lib/asiolink/tests')
-rw-r--r--src/lib/asiolink/tests/process_spawn_unittest.cc28
1 files changed, 9 insertions, 19 deletions
diff --git a/src/lib/asiolink/tests/process_spawn_unittest.cc b/src/lib/asiolink/tests/process_spawn_unittest.cc
index 7314447582..76706543f0 100644
--- a/src/lib/asiolink/tests/process_spawn_unittest.cc
+++ b/src/lib/asiolink/tests/process_spawn_unittest.cc
@@ -68,7 +68,11 @@ public:
io_signal_set_->remove(SIGCHLD);
io_signal_set_.reset();
// Make sure the cancel handler for the IOSignalSet is called.
- io_service_->poll();
+ io_service_->restart();
+ try {
+ io_service_->poll();
+ } catch (...) {
+ }
}
/// @brief Method used as the IOSignalSet handler.
@@ -98,6 +102,7 @@ public:
/// @brief Failsafe timer expiration handler.
void testTimerHandler() {
io_service_->stop();
+ FAIL() << "Test Time: " << test_time_ms_ << " expired";
}
};
@@ -119,8 +124,6 @@ TEST_F(ProcessSpawnTest, spawnWithArgs) {
io_service_->runOne();
// waitForProcess handler.
- io_service_->runOne();
-
// ProcessSpawnTest::processSignal handler.
io_service_->runOne();
@@ -155,8 +158,6 @@ TEST_F(ProcessSpawnTest, spawnWithArgsAndEnvVars) {
io_service_->runOne();
// waitForProcess handler.
- io_service_->runOne();
-
// ProcessSpawnTest::processSignal handler.
io_service_->runOne();
@@ -189,14 +190,15 @@ TEST_F(ProcessSpawnTest, spawnTwoProcesses) {
io_service_->runOne();
// waitForProcess handler.
- io_service_->runOne();
-
// ProcessSpawnTest::processSignal handler.
io_service_->runOne();
// Poll to be sure.
io_service_->poll();
+ ASSERT_EQ(1, processed_signals_.size());
+ ASSERT_EQ(SIGCHLD, processed_signals_[0]);
+
pid_t pid2 = 0;
ASSERT_NO_THROW(pid2 = process.spawn());
@@ -207,8 +209,6 @@ TEST_F(ProcessSpawnTest, spawnTwoProcesses) {
io_service_->runOne();
// waitForProcess handler.
- io_service_->runOne();
-
// ProcessSpawnTest::processSignal handler.
io_service_->runOne();
@@ -246,8 +246,6 @@ TEST_F(ProcessSpawnTest, spawnNoArgs) {
io_service_->runOne();
// waitForProcess handler.
- io_service_->runOne();
-
// ProcessSpawnTest::processSignal handler.
io_service_->runOne();
@@ -269,8 +267,6 @@ TEST_F(ProcessSpawnTest, spawnNoArgs) {
io_service_->runOne();
// waitForProcess handler.
- io_service_->runOne();
-
// ProcessSpawnTest::processSignal handler.
io_service_->runOne();
@@ -347,8 +343,6 @@ TEST_F(ProcessSpawnTest, isRunning) {
io_service_->runOne();
// waitForProcess handler.
- io_service_->runOne();
-
// ProcessSpawnTest::processSignal handler.
io_service_->runOne();
@@ -379,8 +373,6 @@ TEST_F(ProcessSpawnTest, inheritEnv) {
io_service_->runOne();
// waitForProcess handler.
- io_service_->runOne();
-
// ProcessSpawnTest::processSignal handler.
io_service_->runOne();
@@ -415,8 +407,6 @@ TEST_F(ProcessSpawnTest, inheritEnvWithParentVar) {
io_service_->runOne();
// waitForProcess handler.
- io_service_->runOne();
-
// ProcessSpawnTest::processSignal handler.
io_service_->runOne();