Skip to content

fix flaky test test_88_random_error #1171

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jul 18, 2025
Merged

fix flaky test test_88_random_error #1171

merged 2 commits into from
Jul 18, 2025

Conversation

ihrpr
Copy link
Contributor

@ihrpr ihrpr commented Jul 18, 2025

The test is flaky.

  • Replaced sleep-based synchronization with event-based coordination: Instead of using anyio.sleep() to simulate a slow
    operation, the test now uses anyio.Event() to have deterministic control over when the slow request completes
  • Removed unnecessary timing dependencies: The "fast" operation now completes instantly without any sleep, eliminating
    timing-related flakiness
  • Added clean up
  • Simplified the synchronization logic: Removed multiple event objects in favor of a single slow_request event that precisely
    controls the test flow

@ihrpr ihrpr requested a review from a team as a code owner July 18, 2025 15:14
@ihrpr ihrpr requested a review from ochafik July 18, 2025 15:14
Copy link
Contributor

@felixweinberger felixweinberger left a comment

Choose a reason for hiding this comment

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

Nice!

@@ -28,8 +28,7 @@ async def test_notification_validation_error(tmp_path: Path):

server = Server(name="test")
request_count = 0
slow_request_started = anyio.Event()
slow_request_complete = anyio.Event()
slow_request = anyio.Event()
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: slow_request_lock to make it obvious what this is when reading the test further down

# Wait for slow request to complete in the background
with anyio.fail_after(1): # Timeout after 1 second
await slow_request_complete.wait()
# release the slow request not to have hagning process
Copy link
Contributor

Choose a reason for hiding this comment

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

nit: hanging typo

@ihrpr ihrpr merged commit 0b1b52b into main Jul 18, 2025
13 checks passed
@ihrpr ihrpr deleted the ihrpr/fix-flaky-88-test branch July 18, 2025 15:21
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.

2 participants