Skip to content

Commit c340ad4

Browse files
committed
Fix test_timing flakiness under Windows:
Observed: ``` > assert delay_ms <= elapsed_time_ms < delay_ms + generous_tolerance E assert 500.0 <= 490.03173828125 test_event.py:41: AssertionError ``` The generous_tolerance also needs to be applied when checking the lower bound.
1 parent 96d3ba0 commit c340ad4

File tree

1 file changed

+8
-2
lines changed

1 file changed

+8
-2
lines changed

cuda_core/tests/test_event.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
# this software and related documentation outside the terms of the EULA
77
# is strictly prohibited.
88

9+
import os
910
import time
1011

1112
import pytest
@@ -37,8 +38,13 @@ def test_timing(init_cuda, enable_timing):
3738
# We only want to exercise the __sub__ method, this test is not meant
3839
# to stress-test the CUDA driver or time.sleep().
3940
delay_ms = delay_seconds * 1000
40-
generous_tolerance = 20
41-
assert delay_ms <= elapsed_time_ms < delay_ms + generous_tolerance
41+
if os.name == "nt": # noqa: SIM108
42+
# Windows timer resolution is typically limited to 15.6 ms by default.
43+
generous_tolerance = 100
44+
else:
45+
# Most modern Linux kernels have a default timer resolution of 1 ms.
46+
generous_tolerance = 20
47+
assert delay_ms - generous_tolerance <= elapsed_time_ms < delay_ms + generous_tolerance
4248
else:
4349
with pytest.raises(RuntimeError) as e:
4450
elapsed_time_ms = e2 - e1

0 commit comments

Comments
 (0)