From 7bc1b1a0a44ba168eda4c23a1b3aa8f9e7a0edf5 Mon Sep 17 00:00:00 2001 From: Nadav Elkabets Date: Sat, 2 May 2026 21:44:33 +0000 Subject: [PATCH] Added tolerance based on clock resolution to prevent test failure on windows Signed-off-by: Nadav Elkabets --- rclpy/test/test_async_clock.py | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/rclpy/test/test_async_clock.py b/rclpy/test/test_async_clock.py index c47ec967c..eb73150ac 100644 --- a/rclpy/test/test_async_clock.py +++ b/rclpy/test/test_async_clock.py @@ -13,6 +13,7 @@ # limitations under the License. import asyncio +import time import pytest @@ -123,16 +124,17 @@ async def timed(duration): async with asyncio.timeout(5): async with asyncio.TaskGroup() as tg: - t_long = tg.create_task(timed(0.2)) - t_short = tg.create_task(timed(0.05)) - t_mid = tg.create_task(timed(0.1)) - - # Each waiter respected its requested duration (sleep never fires early) - assert t_long.result() >= 0.2 - assert t_mid.result() >= 0.1 - assert t_short.result() >= 0.05 - # Concurrent completes at ~0.2s; serial would be 0.35s. - assert t_long.result() < 0.3 + t_long = tg.create_task(timed(0.5)) + t_short = tg.create_task(timed(0.1)) + t_mid = tg.create_task(timed(0.25)) + + # asyncio loop.call_later may fire up to one clock tick early + tol = time.get_clock_info('monotonic').resolution + # allowed loop overshoot + slack = 0.1 + assert 0.1 - tol <= t_short.result() < 0.1 + slack + assert 0.25 - tol <= t_mid.result() < 0.25 + slack + assert 0.5 - tol <= t_long.result() < 0.5 + slack @pytest.mark.asyncio