Skip to content

replace explicit sleep with polling in animation tests#1697

Merged
gaborbernat merged 5 commits intopypa:mainfrom
pareshjoshij:fix/flaky-animation-tests
Mar 18, 2026
Merged

replace explicit sleep with polling in animation tests#1697
gaborbernat merged 5 commits intopypa:mainfrom
pareshjoshij:fix/flaky-animation-tests

Conversation

@pareshjoshij
Copy link
Contributor

@pareshjoshij pareshjoshij commented Nov 26, 2025

Fixes #1696
Refactor check_animate_output to use a polling loop instead of time.sleep(). This eliminates race conditions causing flaky failures on CI runners and speeds up local execution.

  • Removed rigid sleep calculations based on frame count.

  • Added while loop to capture stderr until expected length is reached.

  • Simplified test_env_no_animate sleep logic.

  • I have added a news fragment under changelog.d/ (if the patch affects the end users)

Summary of changes

Replaced the unstable time.sleep() synchronization in check_animate_output (inside tests/test_animate.py) with a polling loop.

Instead of waiting a fixed duration (which causes flakes on slow CI runners), the test now waits for the exact number of characters to appear in stderr. This makes the test deterministic and significantly faster on local machines.

Test plan

Tested by running the animation tests locally:

pytest tests/test_animate.py

pareshjoshij and others added 3 commits November 26, 2025 23:02
efactor `check_animate_output` to use a polling loop instead of `time.sleep()`.
This eliminates race conditions causing flaky failures on CI runners and speeds up local execution.

- Removed rigid sleep calculations based on frame count.
- Added `while` loop to capture stderr until expected length is reached.
- Simplified `test_env_no_animate` sleep logic.
@pareshjoshij pareshjoshij reopened this Dec 30, 2025
@gaborbernat gaborbernat force-pushed the main branch 2 times, most recently from 4279653 to 5cc32a6 Compare March 17, 2026 02:19
# and to capture all its characters.
time.sleep(extra_after_thread_time)
# POLLING LOOP: Keep reading until we get the expected data
while time.time() - start_time < timeout:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You need to use default_timer, otherwise DST will kill you.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@gaborbernat Good call. Fixed in the latest commit using default_timer(). Thanks!

@gaborbernat gaborbernat marked this pull request as draft March 17, 2026 17:59
@gaborbernat gaborbernat marked this pull request as ready for review March 18, 2026 13:01
@gaborbernat gaborbernat merged commit f8534d1 into pypa:main Mar 18, 2026
11 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Flaky Tests: Replace time.sleep race conditions in test_animate.py with deterministic assertions

2 participants