From 5805edc3dc5e3072389e5370ce5b68e4679771ce Mon Sep 17 00:00:00 2001 From: evgeny Date: Sat, 10 Oct 2026 13:25:04 +0200 Subject: [PATCH] tests: shorten mock NTP and DNS shutdown waits --- tests/test_async_dns.c | 7 ++++++- tests/test_ntp.c | 14 ++++++++++---- 2 files changed, 16 insertions(+), 5 deletions(-) diff --git a/tests/test_async_dns.c b/tests/test_async_dns.c index 5734647c..3af0c2a6 100644 --- a/tests/test_async_dns.c +++ b/tests/test_async_dns.c @@ -106,7 +106,8 @@ static void* dns_server_thread(void* arg) { uint8_t buf[512]; while (g_server_running) { fd_set fds; FD_ZERO(&fds); FD_SET(sock, &fds); - struct timeval tv = {1, 0}; + // Таймаут DNS-запроса задаёт opts; select ограничивает только ожидание остановки сервера. + struct timeval tv = {0, 10000}; int r = select((int)(sock + 1), &fds, NULL, NULL, &tv); if (r <= 0) continue; @@ -184,6 +185,7 @@ int main(void) { debug_config_init(); debug_set_level(DEBUG_LEVEL_WARN); + debug_set_category_level(DEBUG_CATEGORY_GENERAL, DEBUG_LEVEL_INFO); debug_set_category_level(DEBUG_CATEGORY_SOCKET, DEBUG_LEVEL_INFO); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "=== async_dns test ==="); @@ -286,6 +288,9 @@ fail: cleanup: if (ua) uasync_destroy(ua, 0); + uint64_t stop_started = get_time_us(); if (srv_started) { g_server_running = 0; pthread_join(srv, NULL); } + DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "test DNS server stopped: started=%d elapsed_us=%llu", + srv_started, (unsigned long long)(get_time_us() - stop_started)); return result; } diff --git a/tests/test_ntp.c b/tests/test_ntp.c index 5b0119ae..8c082683 100644 --- a/tests/test_ntp.c +++ b/tests/test_ntp.c @@ -86,7 +86,8 @@ static void* test_server_thread(void* arg) { fd_set fds; FD_ZERO(&fds); FD_SET(sock, &fds); - tv.tv_sec = 1; tv.tv_usec = 0; + // Таймаут select нужен только для быстрой остановки тестового сервера. + tv.tv_sec = 0; tv.tv_usec = 10000; int r = select((int)(sock + 1), &fds, NULL, NULL, &tv); if (r <= 0) continue; @@ -172,7 +173,7 @@ static void* dns_server_thread(void* arg) { uint8_t buf[512]; while (g_dns_running) { fd_set fds; FD_ZERO(&fds); FD_SET(sock, &fds); - struct timeval tv = {1, 0}; + struct timeval tv = {0, 10000}; int r = select((int)(sock + 1), &fds, NULL, NULL, &tv); if (r <= 0) continue; struct sockaddr_in client; socklen_t cl = sizeof(client); @@ -243,6 +244,7 @@ int main(void) { debug_config_init(); debug_set_level(DEBUG_LEVEL_WARN); debug_set_categories(DEBUG_CATEGORY_GENERAL); + debug_set_category_level(DEBUG_CATEGORY_GENERAL, DEBUG_LEVEL_INFO); DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "=== NTP Test ==="); @@ -297,7 +299,11 @@ int main(void) { DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "NTP Test PASSED"); cleanup: - if (server_started) { g_server_running = 0; pthread_join(server_thread, NULL); } - if (dns_started) { g_dns_running = 0; pthread_join(dns_thread, NULL); } + g_server_running = g_dns_running = 0; + uint64_t stop_started = get_time_us(); + if (server_started) pthread_join(server_thread, NULL); + if (dns_started) pthread_join(dns_thread, NULL); + DEBUG_INFO(DEBUG_CATEGORY_GENERAL, "test NTP servers stopped: ntp=%d dns=%d elapsed_us=%llu", + server_started, dns_started, (unsigned long long)(get_time_us() - stop_started)); return result; }