Skip to content

Commit 54e07ed

Browse files
committed
TST: Update some times for interactive timer test on CI
1 parent 43ef15e commit 54e07ed

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

lib/matplotlib/tests/test_backends_interactive.py

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -654,11 +654,13 @@ def _impl_test_interactive_timers():
654654
assert mock_single_shot.call_count == 1, \
655655
f"Singleshot: Expected 1 call, got {mock_single_shot.call_count}"
656656

657-
# 250ms timer triggers and the callback takes 150ms to run
658-
# Test that we don't drift and that we get called on every 250ms
659-
# firing and not every 400ms
660-
timer_repeating.interval = 250
661-
mock_repeating.side_effect = lambda: time.sleep(0.15)
657+
# 500ms timer triggers and the callback takes 400ms to run
658+
# Test that we don't drift and that we get called on every 500ms
659+
# firing and not every 900ms
660+
timer_repeating.interval = 500
661+
# sleep for 80% of the interval
662+
sleep_time = timer_repeating.interval / 1000 * 0.8
663+
mock_repeating.side_effect = lambda: time.sleep(sleep_time)
662664
# calling start() again on a repeating timer should remove the old
663665
# one, so we don't want double the number of calls here either because
664666
# two timers are potentially running.
@@ -668,18 +670,21 @@ def _impl_test_interactive_timers():
668670
timer_single_shot.stop()
669671
timer_single_shot.start()
670672

671-
event_loop_time = 2 # in seconds
673+
# CI resources are inconsistent, so we need to allow for some slop
674+
event_loop_time = 10 if os.getenv("CI") else 3 # in seconds
672675
expected_calls = int(event_loop_time / (timer_repeating.interval / 1000))
673676

674677
t_start = time.perf_counter()
675678
fig.canvas.start_event_loop(event_loop_time)
676679
t_loop = time.perf_counter() - t_start
677-
# Should be around 2s, but allow for some slop on CI. We want to make sure
678-
# we aren't getting 2 + (callback time) 0.5s/iteration, which would be 4+ s.
679-
assert 1.8 < t_loop < 3, \
680-
f"Event loop: Expected to run for around 2s, but ran for {t_loop:.2f}s"
680+
# Should be around event_loop_time, but allow for some slop on CI.
681+
# We want to make sure we aren't getting
682+
# event_loop_time + (callback time)*niterations
683+
assert event_loop_time * 0.95 < t_loop < event_loop_time / 0.7, \
684+
f"Event loop: Expected to run for around {event_loop_time}s, " \
685+
f"but ran for {t_loop:.2f}s"
681686
# Not exact timers, so add some slop. (Quite a bit for CI resources)
682-
assert abs(mock_repeating.call_count - expected_calls) <= 2, \
687+
assert abs(mock_repeating.call_count - expected_calls) / expected_calls <= 0.3, \
683688
f"Slow callback: Expected {expected_calls} calls, " \
684689
f"got {mock_repeating.call_count}"
685690
assert mock_single_shot.call_count == 2, \

0 commit comments

Comments
 (0)