@@ -675,11 +675,13 @@ def _impl_test_interactive_timers():
675
675
assert mock_single_shot .call_count == 1 , \
676
676
f"Singleshot: Expected 1 call, got{ mock_single_shot .call_count } "
677
677
678
- # 250ms timer triggers and the callback takes 150ms to run
679
- # Test that we don't drift and that we get called on every 250ms
680
- # firing and not every 400ms
681
- timer_repeating .interval = 250
682
- mock_repeating .side_effect = lambda :time .sleep (0.15 )
678
+ # 500ms timer triggers and the callback takes 400ms to run
679
+ # Test that we don't drift and that we get called on every 500ms
680
+ # firing and not every 900ms
681
+ timer_repeating .interval = 500
682
+ # sleep for 80% of the interval
683
+ sleep_time = timer_repeating .interval / 1000 * 0.8
684
+ mock_repeating .side_effect = lambda :time .sleep (sleep_time )
683
685
# calling start() again on a repeating timer should remove the old
684
686
# one, so we don't want double the number of calls here either because
685
687
# two timers are potentially running.
@@ -689,18 +691,21 @@ def _impl_test_interactive_timers():
689
691
timer_single_shot .stop ()
690
692
timer_single_shot .start ()
691
693
692
- event_loop_time = 2 # in seconds
694
+ # CI resources are inconsistent, so we need to allow for some slop
695
+ event_loop_time = 10 if os .getenv ("CI" )else 3 # in seconds
693
696
expected_calls = int (event_loop_time / (timer_repeating .interval / 1000 ))
694
697
695
698
t_start = time .perf_counter ()
696
699
fig .canvas .start_event_loop (event_loop_time )
697
700
t_loop = time .perf_counter ()- t_start
698
- # Should be around 2s, but allow for some slop on CI. We want to make sure
699
- # we aren't getting 2 + (callback time) 0.5s/iteration, which would be 4+ s.
700
- assert 1.8 < t_loop < 3 , \
701
- f"Event loop: Expected to run for around 2s, but ran for{ t_loop :.2f} s"
701
+ # Should be around event_loop_time, but allow for some slop on CI.
702
+ # We want to make sure we aren't getting
703
+ # event_loop_time + (callback time)*niterations
704
+ assert event_loop_time * 0.95 < t_loop < event_loop_time / 0.7 , \
705
+ f"Event loop: Expected to run for around{ event_loop_time } s, " \
706
+ f"but ran for{ t_loop :.2f} s"
702
707
# Not exact timers, so add some slop. (Quite a bit for CI resources)
703
- assert abs (mock_repeating .call_count - expected_calls )<= 2 , \
708
+ assert abs (mock_repeating .call_count - expected_calls )/ expected_calls <= 0.3 , \
704
709
f"Slow callback: Expected{ expected_calls } calls, " \
705
710
f"got{ mock_repeating .call_count } "
706
711
assert mock_single_shot .call_count == 2 , \