Skip to content

Commit c351bcf

Browse files
authored
Fix flaky error counter test (#124)
The timing for this test was too tight, which caused it to be flaky.
1 parent 84bac26 commit c351bcf

File tree

1 file changed

+7
-8
lines changed

1 file changed

+7
-8
lines changed

tests/test_errcount.py

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,18 +71,17 @@ def test_rolling_error_counter_count_is_rolling():
7171
"""Check that the error counter is actually rolling by incrementally adding
7272
and sleeping. At some point we should see the counter decrease because
7373
an entry has expired."""
74-
rec = RollingErrorCounter(0.03, 5)
74+
# Init an error counter that rolls every 0.05 seconds.
75+
# Trying to use a shorter interval, such as 0.01, is flaky in CI.
76+
# We add 2 errors, then sleep 0.1 seconds to ensure the they have expired
77+
# before we add a new one and check the count.
78+
rec = RollingErrorCounter(0.05, 5)
7579
rec.add()
76-
assert rec.count() == 1
77-
time.sleep(0.01)
7880
rec.add()
7981
assert rec.count() == 2
80-
time.sleep(0.01)
81-
rec.add()
82-
assert rec.count() == 3
83-
time.sleep(0.011) # just to be sure the first one expired
82+
time.sleep(0.1) # Double duration just to be sure the first two expired
8483
rec.add()
85-
assert rec.count() == 3
84+
assert rec.count() == 1
8685

8786

8887
def test_rolling_error_counter_tolerance_exceeded():

0 commit comments

Comments
 (0)