From 4d4fb34075c90d8f2f9ff81890152ab60f65e48e Mon Sep 17 00:00:00 2001 From: Brad House Date: Thu, 28 Sep 2023 07:19:16 -0400 Subject: [PATCH] Test Harness: use ares_timeout() to calculate the value to pass to select() these days. (#555) The test framework was using 100ms timeout passed to select(), and not using ares_timeout() to calculate the actual recommended value based on the queries in queue. Using ares_timeout() tests the functionality of ares_timeout() itself and will provide more responsive results. Fix By: Brad House (@bradh352) --- test/ares-test.cc | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/test/ares-test.cc b/test/ares-test.cc index 65dc16db..d904322a 100644 --- a/test/ares-test.cc +++ b/test/ares-test.cc @@ -101,9 +101,11 @@ void ProcessWork(ares_channel channel, } } - // Wait for activity or timeout. - tv.tv_sec = 0; - tv.tv_usec = 100000; // 100ms + /* If ares_timeout returns NULL, it means there are no requests in queue, + * so we can break out */ + if (ares_timeout(channel, NULL, &tv) == NULL) + return; + count = select(nfds, &readers, &writers, nullptr, &tv); if (count < 0) { fprintf(stderr, "select() failed, errno %d\n", errno);