]> git.ipfire.org Git - thirdparty/kea.git/commitdiff
[#4247] Ported improvements
authorFrancis Dupont <fdupont@isc.org>
Fri, 5 Dec 2025 09:48:51 +0000 (10:48 +0100)
committerFrancis Dupont <fdupont@isc.org>
Mon, 8 Dec 2025 14:45:35 +0000 (15:45 +0100)
src/hooks/dhcp/high_availability/tests/ha_test.cc
src/lib/asiolink/testutils/test_server_unix_socket.cc
src/lib/testutils/threaded_test.cc

index 96130b1fcbf2ef191422eb2593f89bac7c28d1cb..67da039013ad7b32ebb90a271954b727251985e2 100644 (file)
@@ -15,6 +15,7 @@
 #include <dhcp/dhcp6.h>
 #include <dhcp/duid.h>
 #include <dhcp/hwaddr.h>
+#include <dhcp/iface_mgr.h>
 #include <dhcp/option.h>
 #include <dhcp/option_int.h>
 #include <dhcpsrv/cfgmgr.h>
@@ -54,6 +55,8 @@ namespace test {
 HATest::HATest()
     : io_service_(new IOService()),
       network_state_(new NetworkState()) {
+    // Just make sure that the interface manager is created in the main thread.
+    IfaceMgr::instance();
 }
 
 HATest::~HATest() {
@@ -115,13 +118,25 @@ HATest::runIOServiceInThread() {
 
     io_service_->post(std::bind(&HATest::signalServiceRunning, this, std::ref(running),
                                 std::ref(mutex), std::ref(condvar)));
+
+    // IfaceMgr::instance().setCheckThreadId(false);
+
+    auto f = [](IOServicePtr io_service) {
+        try {
+            io_service->run();
+        } catch (std::exception& ex) {
+            ADD_FAILURE() << "error while running IOService::run: " << ex.what();
+        } catch (...) {
+            ADD_FAILURE() << "error while running IOService::run";
+        }
+        // IfaceMgr::instance().setCheckThreadId(true);
+    };
+
     boost::shared_ptr<std::thread>
-        th(new std::thread(std::bind(&IOService::run, io_service_.get())));
+        th(new std::thread(std::bind(f, io_service_)));
 
     std::unique_lock<std::mutex> lock(mutex);
-    while (!running) {
-        condvar.wait(lock);
-    }
+    condvar.wait(lock, [&]() { return (running); });
 
     return (th);
 }
@@ -147,7 +162,6 @@ HATest::signalServiceRunning(bool& running, std::mutex& mutex,
     condvar.notify_one();
 }
 
-
 void
 HATest::checkThatTimeIsParsable(ElementPtr const& node, bool const null_expected) {
     ConstElementPtr system_time(node->get("system-time"));
@@ -325,7 +339,6 @@ HATest::createValidHubJsonConfiguration() const {
     return (Element::fromJSON(config_text.str()));
 }
 
-
 HAConfigPtr
 HATest::createValidConfiguration(const HAConfig::HAMode& ha_mode) const {
     auto config_storage = HAConfigParser::parse(createValidJsonConfiguration(ha_mode));
@@ -377,7 +390,6 @@ HATest::randomKey(const size_t key_size) const {
     return (key);
 }
 
-
 Pkt4Ptr
 HATest::createMessage4(const uint8_t msg_type, const uint8_t hw_address_seed,
                        const uint8_t client_id_seed, const uint16_t secs) const {
index 00f211cb62a96e21bc53c49ee152f899f2600dcd..7fb181a74150f13d958b798ec69bf0836c7098d9 100644 (file)
@@ -307,9 +307,7 @@ TestServerUnixSocket::signalRunning() {
 void
 TestServerUnixSocket::waitForRunning() {
     std::unique_lock<std::mutex> lock(mutex_);
-    while (!running_) {
-        condvar_.wait(lock);
-    }
+    condvar_.wait(lock, [&]() { return (running_); });
 }
 
 void
index 88cb846e9f951eee802adc2816acf8ce4232c509..83a65a6895bf995a211bd4e8008c926c70797744 100644 (file)
@@ -43,9 +43,7 @@ ThreadedTest::signalStopped() {
 void
 ThreadedTest::doWait(bool& flag) {
     std::unique_lock<std::mutex> lock(mutex_);
-    while (!flag) {
-        condvar_.wait(lock);
-    }
+    condvar_.wait(lock, [&]() { return (flag); });
 }
 
 void