fix: replace fixed sleeps with polling in flaky TestChildProcessCleanup tests#2071
Open
BabyChrist666 wants to merge 2 commits intomodelcontextprotocol:mainfrom
Open
Conversation
…delcontextprotocol#1775) The three flaky tests in TestChildProcessCleanup fail intermittently on macOS CI because fixed-duration sleeps (0.5s-1.0s) aren't enough for child processes to start writing on slow CI machines. Replace the fixed `anyio.sleep()` + size assertion pattern with a `_wait_for_file_growth()` helper that polls until the file exists, has content, and is actively growing, with a 10s timeout. This eliminates the race condition where assertions fire before processes have started. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
The timeout raise and file-not-yet-exists branch are safety nets that don't execute in normal test runs. Mark them with coverage pragmas to satisfy the 100% coverage requirement. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Closes #1775
The three tests in
TestChildProcessCleanup(test_basic_child_process_cleanup,test_nested_process_tree,test_early_parent_exit) fail intermittently on macOS CI because fixed-durationanyio.sleep()calls (0.5s–1.0s) aren't always enough for child processes to start writing to their marker files on slow CI machines. The assertions then checkassert 0 > 0because the file is still empty.Root cause
Fix
Added a
_wait_for_file_growth()helper that polls the marker file until it exists, has content, and is actively growing — with a generous 10-second timeout. This eliminates the race condition entirely:What changed
_wait_for_file_growth()async helper (polls file size at 0.2s intervals, 10s timeout)Test plan
🤖 Generated with Claude Code