44import ipaddress
55import itertools
66import sys
7- import time
87import weakref
98from collections .abc import Iterator
109from math import ceil , modf
@@ -353,22 +352,20 @@ def test_timeout_handle(event_loop: asyncio.AbstractEventLoop) -> None:
353352 assert not handle ._callbacks
354353
355354
356- @pytest .mark .skipif (
357- time .get_clock_info ("monotonic" ).resolution > 0.001 ,
358- reason = "loop.time() resolution is coarser than the test's 1ms tolerance" ,
359- )
360355def test_when_timeout_smaller_second (event_loop : asyncio .AbstractEventLoop ) -> None :
361356 timeout = 0.1
362357
363358 handle = helpers .TimeoutHandle (event_loop , timeout )
364- timer = event_loop .time () + timeout
359+ before = event_loop .time ()
365360 start_handle = handle .start ()
361+ after = event_loop .time ()
366362 assert start_handle is not None
367363 when = start_handle .when ()
368364 handle .close ()
369365
366+ # Below the ceil threshold the deadline keeps sub-second precision.
370367 assert isinstance (when , float )
371- assert when - timer == pytest . approx ( 0 , abs = 0.001 )
368+ assert before + timeout <= when <= after + timeout
372369
373370
374371def test_when_timeout_smaller_second_with_low_threshold (
@@ -377,14 +374,15 @@ def test_when_timeout_smaller_second_with_low_threshold(
377374 timeout = 0.1
378375
379376 handle = helpers .TimeoutHandle (event_loop , timeout , 0.01 )
380- timer = event_loop .time () + timeout
377+ before = event_loop .time ()
381378 start_handle = handle .start ()
379+ after = event_loop .time ()
382380 assert start_handle is not None
383381 when = start_handle .when ()
384382 handle .close ()
385383
386384 assert isinstance (when , int )
387- assert when == ceil (timer )
385+ assert ceil ( before + timeout ) <= when <= ceil (after + timeout )
388386
389387
390388def test_timeout_handle_cb_exc (event_loop : asyncio .AbstractEventLoop ) -> None :
0 commit comments