]> git.ipfire.org Git - thirdparty/pdns.git/commitdiff
dnsdist: Prevent spurious failures of the async unit tests
authorRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 15 Sep 2023 09:32:33 +0000 (11:32 +0200)
committerRemi Gacogne <remi.gacogne@powerdns.com>
Fri, 15 Sep 2023 09:32:33 +0000 (11:32 +0200)
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 <number of HT cores>`.

pdns/dnsdistdist/test-dnsdistasync.cc

index d74d2e64b5d6a80020961fd5484f99932f6911b4..82ed4b15e54ee05b83c09ba6e0d1e7cbc8a3d410 100644 (file)
@@ -112,23 +112,28 @@ BOOST_AUTO_TEST_CASE(test_TimeoutFailClose)
   auto holder = std::make_unique<dnsdist::AsynchronousHolder>(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<DummyQuerySender> sender{nullptr};
   {
+    // timeout in 10 ms
+    const timeval add{0, 10000};
     auto query = std::make_unique<DummyCrossProtocolQuery>();
     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);