diff options
author | Razvan Becheriu <razvan@isc.org> | 2021-02-18 12:22:31 +0100 |
---|---|---|
committer | Razvan Becheriu <razvan@isc.org> | 2021-02-18 18:23:57 +0100 |
commit | a4c30c291b1dfd2e253cf2f6d5f652c8c4de3ffc (patch) | |
tree | e53700768a1c1b573f4acd72636d79151ed121f0 | |
parent | [#899] fixed unittests (diff) | |
download | kea-a4c30c291b1dfd2e253cf2f6d5f652c8c4de3ffc.tar.xz kea-a4c30c291b1dfd2e253cf2f6d5f652c8c4de3ffc.zip |
[#899] added more unittests
-rw-r--r-- | src/lib/asiolink/io_service_signal.cc | 2 | ||||
-rw-r--r-- | src/lib/asiolink/process_spawn.cc | 2 | ||||
-rw-r--r-- | src/lib/asiolink/tests/io_service_signal_unittests.cc | 22 | ||||
-rw-r--r-- | src/lib/asiolink/tests/process_spawn_unittest.cc | 21 |
4 files changed, 45 insertions, 2 deletions
diff --git a/src/lib/asiolink/io_service_signal.cc b/src/lib/asiolink/io_service_signal.cc index d75fac67c5..51dca8da13 100644 --- a/src/lib/asiolink/io_service_signal.cc +++ b/src/lib/asiolink/io_service_signal.cc @@ -100,7 +100,7 @@ IOSignalSetImpl::remove(int signum) { signal_set_.remove(signum); } catch (const boost::system::system_error& ex) { isc_throw(isc::Unexpected, - "Failed to add signal " << signum << ": " << ex.what()); + "Failed to remove signal " << signum << ": " << ex.what()); } } diff --git a/src/lib/asiolink/process_spawn.cc b/src/lib/asiolink/process_spawn.cc index f739f1bd6a..3ccea308eb 100644 --- a/src/lib/asiolink/process_spawn.cc +++ b/src/lib/asiolink/process_spawn.cc @@ -303,7 +303,7 @@ bool ProcessSpawnImpl::isAnyRunning() const { lock_guard<std::mutex> lk(mutex_); if (process_collection_.find(this) != process_collection_.end()) { - for (auto& proc : process_collection_[this]) { + for (auto const& proc : process_collection_[this]) { if (proc.second->running_) { return (true); } diff --git a/src/lib/asiolink/tests/io_service_signal_unittests.cc b/src/lib/asiolink/tests/io_service_signal_unittests.cc index f338b716aa..d8564d341b 100644 --- a/src/lib/asiolink/tests/io_service_signal_unittests.cc +++ b/src/lib/asiolink/tests/io_service_signal_unittests.cc @@ -132,6 +132,28 @@ TEST_F(IOSignalTest, singleSignalTest) { // Now check that signal value is correct. EXPECT_EQ(SIGINT, processed_signals_[0]); + + // Set test fail safe. + setTestTime(1000); + + // Unregister the receive of SIGINT. + ASSERT_NO_THROW(io_signal_set_->remove(SIGINT)); + + // Use TimedSignal to generate SIGINT 100 ms after we start IOService::run. + TimedSignal sig_int_too_late(*io_service_, SIGINT, 100); + + // The first handler executed is the IOSignal's internal timer expire + // callback. + io_service_->run_one(); + + // The next handler executed is IOSignal's handler. + io_service_->run_one(); + + // Polling once to be sure. + io_service_->poll(); + + // Verify that we did not process the signal. + ASSERT_EQ(1, processed_signals_.size()); } // Test verifies that signals can be delivered rapid-fire without falling over. diff --git a/src/lib/asiolink/tests/process_spawn_unittest.cc b/src/lib/asiolink/tests/process_spawn_unittest.cc index a38c054a08..6f7c9dcf2c 100644 --- a/src/lib/asiolink/tests/process_spawn_unittest.cc +++ b/src/lib/asiolink/tests/process_spawn_unittest.cc @@ -249,6 +249,27 @@ TEST_F(ProcessSpawnTest, spawnNoArgs) { ASSERT_EQ(SIGCHLD, processed_signals_[0]); EXPECT_EQ(32, process.getExitStatus(pid)); + + ASSERT_NO_THROW(pid = process.spawn(true)); + + // Set test fail safe. + setTestTime(1000); + + // The next handler executed is IOSignal's handler. + io_service_->run_one(); + + // The first handler executed is the IOSignal's internal timer expire + // callback. + io_service_->run_one(); + + // Polling once to be sure. + io_service_->poll(); + + ASSERT_EQ(2, processed_signals_.size()); + ASSERT_EQ(SIGCHLD, processed_signals_[0]); + ASSERT_EQ(SIGCHLD, processed_signals_[1]); + + EXPECT_THROW(process.getExitStatus(pid), InvalidOperation); } // This test verifies that the EXIT_FAILURE code is returned when |