Remove raciness from test_is_process_on_port_concurrent_access#5826
Merged
adhami3310 merged 1 commit intomainfrom Sep 27, 2025
Merged
Conversation
This test was consistently failing on macos github actions runners.
Contributor
There was a problem hiding this comment.
Greptile Overview
Summary
This PR fixes a race condition in the test_is_process_on_port_concurrent_access test that was causing failures on macOS GitHub Actions runners. The fix replaces unreliable time.sleep() calls with proper thread synchronization using threading.Event objects and robust polling with AppHarness._poll_for().
- Replaced
time.sleep()timing dependencies withthreading.Eventsynchronization - Added proper timeout handling using
DEFAULT_TIMEOUTconstant - Used
AppHarness._poll_for()for reliable polling instead of fixed delays - Added proper cleanup with try/finally blocks and timeout-aware thread joining
Confidence Score: 5/5
- This PR is safe to merge with minimal risk
- Score reflects a well-implemented race condition fix that follows best practices for thread synchronization, uses existing testing utilities properly, and includes proper timeout handling and cleanup
- No files require special attention
Important Files Changed
File Analysis
| Filename | Score | Overview |
|---|---|---|
| tests/units/utils/test_processes.py | 5/5 | Race condition fixed by replacing time.sleep() with proper threading.Event synchronization and polling |
Sequence Diagram
sequenceDiagram
participant MT as Main Thread
participant ST as Server Thread
participant S as Socket Server
participant EO as is_open Event
participant EC as do_close Event
participant AH as AppHarness._poll_for
MT->>ST: Start thread
ST->>S: Create socket
ST->>S: Bind to port
ST->>S: Listen on port
ST->>EO: Set is_open event
MT->>EO: Wait for is_open (with timeout)
EO-->>MT: Server is ready
MT->>AH: Poll for port occupation
AH->>AH: Check is_process_on_port(shared)
AH-->>MT: Port is occupied (success)
MT->>EC: Set do_close event
ST->>EC: Wait for do_close (with timeout)
EC-->>ST: Close signal received
ST->>S: Close socket
MT->>AH: Poll for port release
AH->>AH: Check not is_process_on_port(shared)
AH-->>MT: Port is released (success)
MT->>ST: Join thread (with timeout)
1 file reviewed, no comments
CodSpeed Performance ReportMerging #5826 will not alter performanceComparing Summary
|
adhami3310
approved these changes
Sep 27, 2025
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.
This test was consistently failing on macos github actions runners.