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 df8a4a0ba..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; @@ -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 {