From 3c79800a45dde886af2a3be0ccced187b31cd5e7 Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Thu, 30 Oct 2025 17:30:33 +0500 Subject: [PATCH 1/2] Add delay - WatchDog test --- lib/ProxySQL_Admin_Tests2.cpp | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lib/ProxySQL_Admin_Tests2.cpp b/lib/ProxySQL_Admin_Tests2.cpp index df8a4a0ba..b7cfd467f 100644 --- a/lib/ProxySQL_Admin_Tests2.cpp +++ b/lib/ProxySQL_Admin_Tests2.cpp @@ -571,7 +571,7 @@ bool RunWatchdogTest(const char* label, ThreadType* worker, unsigned int poll_ti unsigned int missed = worker->watchdog_test__missed_heartbeats; if (missed != last_missed) { last_missed = missed; - proxy_info("Watchdog test: Missed heartbeats: %u\n", missed); + proxy_info("Watchdog test - Missed heartbeats: %u\n", missed); } if (success == false && missed == target_missed) { @@ -584,6 +584,13 @@ bool RunWatchdogTest(const char* label, ThreadType* worker, unsigned int poll_ti worker->watchdog_test__simulated_delay_ms = 0; worker->watchdog_test__missed_heartbeats = 0; + usleep(1000000); + + if (worker->watchdog_test__missed_heartbeats != 0) { + worker->watchdog_test__simulated_delay_ms = 0; + worker->watchdog_test__missed_heartbeats = 0; + } + if (success) { proxy_info("Watchdog test passed. Missed heartbeats: %u\n", target_missed); } else { From 86c17f04d719e8c85af6b8f6ac9971a5d78def3c Mon Sep 17 00:00:00 2001 From: Rahim Kanji Date: Thu, 30 Oct 2025 17:45:50 +0500 Subject: [PATCH 2/2] Replace single sleep with looped delay for simulated watchdog test --- lib/MySQL_Thread.cpp | 5 +++-- lib/PgSQL_Thread.cpp | 5 +++-- lib/ProxySQL_Admin_Tests2.cpp | 8 ++++---- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/lib/MySQL_Thread.cpp b/lib/MySQL_Thread.cpp index 5b2d467c9..de162f0e4 100644 --- a/lib/MySQL_Thread.cpp +++ b/lib/MySQL_Thread.cpp @@ -3394,8 +3394,9 @@ __run_skip_1: #ifdef DEBUG // This block is only used for Watchdog unit tests: // Specifically for PROXYSQLTEST cases 55 0 and 55 1. - if (watchdog_test__simulated_delay_ms) - std::this_thread::sleep_for(std::chrono::milliseconds(watchdog_test__simulated_delay_ms)); + while (watchdog_test__simulated_delay_ms > 0) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } #endif } } diff --git a/lib/PgSQL_Thread.cpp b/lib/PgSQL_Thread.cpp index 6dd5a46d4..ad13d9772 100644 --- a/lib/PgSQL_Thread.cpp +++ b/lib/PgSQL_Thread.cpp @@ -3192,8 +3192,9 @@ void PgSQL_Thread::run() { #ifdef DEBUG // This block is only used for Watchdog unit tests: // Specifically for PROXYSQLTEST cases 55 0 and 55 1. - if (watchdog_test__simulated_delay_ms) - std::this_thread::sleep_for(std::chrono::milliseconds(watchdog_test__simulated_delay_ms)); + while (watchdog_test__simulated_delay_ms > 0) { + std::this_thread::sleep_for(std::chrono::milliseconds(100)); + } #endif } } diff --git a/lib/ProxySQL_Admin_Tests2.cpp b/lib/ProxySQL_Admin_Tests2.cpp index b7cfd467f..9bd06d594 100644 --- a/lib/ProxySQL_Admin_Tests2.cpp +++ b/lib/ProxySQL_Admin_Tests2.cpp @@ -550,13 +550,13 @@ bool RunWatchdogTest(const char* label, ThreadType* worker, unsigned int poll_ti return false; } - proxy_info("Starting Watchdog test for %s threads...\n", label); + proxy_info("Starting Watchdog test for %s threads (poll timeout:%u ms)...\n", label, poll_timeout); const unsigned int target_missed = GloVars.restart_on_missing_heartbeats; - const uint64_t time_per_miss_ms = poll_timeout + 1000 + 200; - const uint64_t total_expected_time_ms = target_missed * time_per_miss_ms; + const unsigned int time_per_miss_ms = poll_timeout + 1000 + 200; + const unsigned int total_expected_time_ms = target_missed * time_per_miss_ms; - worker->watchdog_test__simulated_delay_ms = static_cast(total_expected_time_ms); + worker->watchdog_test__simulated_delay_ms = total_expected_time_ms; const unsigned int timeout_ms = static_cast(total_expected_time_ms * 1.25); constexpr unsigned int poll_interval_ms = 200;