fix: Replace arbitrary sleeps with active server readiness checks in tests #1527
      
        
          +45
        
        
          −98
        
        
          
        
      
    
  
  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.
  
    
  
    
Fixes flaky test failures by replacing arbitrary sleep delays with deterministic server readiness polling across all HTTP server tests.
Motivation and Context
Multiple test files were using either fixed
time.sleep()delays or manual polling loops with inconsistent implementations to wait for servers to start. This approach was problematic because:This PR follows the same approach as #1526, which fixed similar issues in
test_sse_security.py.How Has This Been Tested?
Verified the fix: Ran all affected test suites successfully:
test_streamable_http_security.py: 7 passedtest_sse_security.py: 8 passedtest_ws.py: 4 passedtest_sse.py: 16 passed, 1 skippedtest_streamable_http.py: 33 passedConsistency check: All test files now use the same centralized
wait_for_server()helperPerformance: Tests complete in similar or faster time since they don't wait unnecessarily
Breaking Changes
None. This is purely an internal test improvement with no impact on the public API or user code.
Types of changes
Checklist
Additional context
The new
wait_for_server()helper intests/test_helpers.py:TimeoutErroron true failuresThis follows the principles outlined in the repository's approach to avoiding flaky tests by using active condition checking rather than arbitrary sleeps.