tests: shorten mock NTP and DNS shutdown waits
This commit is contained in:
1 parent
3f9edc88c4
commit
5805edc3dc
2 files changed
+16
-5
No files matched your search
@@ -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;
|
||||
}
|
||||
+10
-4
@@ -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;
|
||||
}
|
||||
Reference in new issue
Block a user