From: Remi Gacogne Date: Fri, 15 Sep 2023 09:32:33 +0000 (+0200) Subject: dnsdist: Prevent spurious failures of the async unit tests X-Git-Tag: dnsdist-1.9.0-alpha1^2~1 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=1237c7f4c55f1e1fba7ba58e95636d18e1a9f823;p=thirdparty%2Fpdns.git dnsdist: Prevent spurious failures of the async unit tests The events should be triggered either almost immediately or after 10 ms, but we have seen many spurious failures on our CI, likely because the box is overloaded, so sleep for up to 100 ms to be sure. I managed to reproduce the issue locally by running this command in parallel of the tests, for reference: `stress --cpu `. --- diff --git a/pdns/dnsdistdist/test-dnsdistasync.cc b/pdns/dnsdistdist/test-dnsdistasync.cc index d74d2e64b5..82ed4b15e5 100644 --- a/pdns/dnsdistdist/test-dnsdistasync.cc +++ b/pdns/dnsdistdist/test-dnsdistasync.cc @@ -112,23 +112,28 @@ BOOST_AUTO_TEST_CASE(test_TimeoutFailClose) auto holder = std::make_unique(false); uint16_t asyncID = 1; uint16_t queryID = 42; - struct timeval ttd; - gettimeofday(&ttd, nullptr); - // timeout in 10 ms - const timeval add{0, 10000}; - ttd = ttd + add; + struct timeval ttd{ + }; std::shared_ptr sender{nullptr}; { + // timeout in 10 ms + const timeval add{0, 10000}; auto query = std::make_unique(); sender = query->d_sender; BOOST_REQUIRE(sender != nullptr); + gettimeofday(&ttd, nullptr); + ttd = ttd + add; holder->push(asyncID, queryID, ttd, std::move(query)); BOOST_CHECK(!holder->empty()); } - // sleep for 20 ms, to be sure - usleep(20000); + // the event should be triggered after 10 ms, but we have seen + // many spurious failures on our CI, likely because the box is + // overloaded, so sleep for up to 100 ms to be sure + for (size_t counter = 0; !holder->empty() && counter < 10; counter++) { + usleep(10000); + } BOOST_CHECK(holder->empty()); BOOST_CHECK(sender->errorRaised); @@ -155,8 +160,13 @@ BOOST_AUTO_TEST_CASE(test_AddingExpiredEvent) holder->push(asyncID, queryID, ttd, std::move(query)); } - // sleep for 20 ms - usleep(20000); + // the expired event should be triggered almost immediately, + // but we have seen many spurious failures on our CI, + // likely because the box is overloaded, so sleep for up to + // 100 ms to be sure + for (size_t counter = 0; !holder->empty() && counter < 10; counter++) { + usleep(10000); + } BOOST_CHECK(holder->empty()); BOOST_CHECK(sender->errorRaised);