@@ -654,11 +654,13 @@ def _impl_test_interactive_timers():
654
654
assert mock_single_shot .call_count == 1 , \
655
655
f"Singleshot: Expected 1 call, got { mock_single_shot .call_count } "
656
656
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 )
662
664
# calling start() again on a repeating timer should remove the old
663
665
# one, so we don't want double the number of calls here either because
664
666
# two timers are potentially running.
@@ -668,18 +670,21 @@ def _impl_test_interactive_timers():
668
670
timer_single_shot .stop ()
669
671
timer_single_shot .start ()
670
672
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
672
675
expected_calls = int (event_loop_time / (timer_repeating .interval / 1000 ))
673
676
674
677
t_start = time .perf_counter ()
675
678
fig .canvas .start_event_loop (event_loop_time )
676
679
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"
681
686
# 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 , \
683
688
f"Slow callback: Expected { expected_calls } calls, " \
684
689
f"got { mock_repeating .call_count } "
685
690
assert mock_single_shot .call_count == 2 , \
0 commit comments