From bf89dc0797fa967e801688c2e80573902dc74ebf Mon Sep 17 00:00:00 2001 From: Michael Carroll Date: Tue, 19 Jun 2018 13:06:30 -0500 Subject: [PATCH] Further expand test tolerance to address flakiness. (#501) * Further expand test tolerance to address flakiness. * Remove newline. --- rclcpp/test/executors/test_multi_threaded_executor.cpp | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/rclcpp/test/executors/test_multi_threaded_executor.cpp b/rclcpp/test/executors/test_multi_threaded_executor.cpp index 6465b28..e6c2bcb 100644 --- a/rclcpp/test/executors/test_multi_threaded_executor.cpp +++ b/rclcpp/test/executors/test_multi_threaded_executor.cpp @@ -71,8 +71,11 @@ TEST_F(TestMultiThreadedExecutor, timer_over_take) { std::atomic_int timer_count {0}; auto timer_callback = [&timer_count, &executor, &system_clock, &last_mutex, &last]() { + // While this tolerance is a little wide, if the bug occurs, the next step will + // happen almost instantly. The purpose of this test is not to measure the jitter + // in timers, just assert that a reasonable amount of time has passed. const double PERIOD = 0.1f; - const double TOLERANCE = 0.01f; + const double TOLERANCE = 0.025f; rclcpp::Time now = system_clock.now(); timer_count++; @@ -88,8 +91,8 @@ TEST_F(TestMultiThreadedExecutor, timer_over_take) { if (diff < PERIOD - TOLERANCE || diff > PERIOD + TOLERANCE) { executor.cancel(); - ASSERT_TRUE(diff > PERIOD - TOLERANCE); - ASSERT_TRUE(diff < PERIOD + TOLERANCE); + ASSERT_GT(diff, PERIOD - TOLERANCE); + ASSERT_LT(diff, PERIOD + TOLERANCE); } } };