]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#899] added more unittests
authorRazvan Becheriu <razvan@isc.org>
Thu, 18 Feb 2021 11:22:31 +0000 (13:22 +0200)
committerRazvan Becheriu <razvan@isc.org>
Thu, 18 Feb 2021 17:23:57 +0000 (19:23 +0200)
src/lib/asiolink/io_service_signal.cc
src/lib/asiolink/process_spawn.cc
src/lib/asiolink/tests/io_service_signal_unittests.cc
src/lib/asiolink/tests/process_spawn_unittest.cc

index d75fac67c503a097d856f5c96afaa6b14412b1f6..51dca8da1307b1dfa2c8d575593eed12044a679b 100644 (file)
@@ -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());
     }
 }
 
index f739f1bd6a807eff5d8ac7c712915e282aafd7da..3ccea308eb7b102971dfbfb50ebfa081434293b8 100644 (file)
@@ -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);
             }
index f338b716aa82589759a0157bdfa8a5273078c8d5..d8564d341b656bc97dfd7386e86ca23c3e29ed6e 100644 (file)
@@ -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.
index a38c054a08a8ff7f272786eb6c1ffe9538bb5ef3..6f7c9dcf2cf24db02ffa09809b782afac1107eba 100644 (file)
@@ -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