fix(selftests): raise mock-server listen backlog so load assertions measure the engine - #597
Merged
Merged
Conversation
…easure the engine
Contributor
There was a problem hiding this comment.
Pull request overview
This PR fixes a platform-specific selftest flake by making the module-scoped mock_server fixture resilient to bursts of concurrent connections on macOS, so the load-engine assertions measure the engine behavior rather than the server’s accept backlog.
Changes:
- Increase the mock HTTP server’s
listen()backlog (request_queue_size) to avoid kernel connection resets under 50–1000 concurrent connection attempts. - Add inline documentation explaining why the failure manifested as a misleading non-zero
failure_rateon macOS.
💡 Add a code-review agent skill or configure MCP servers for context-aware, tailored reviews. Learn more in the docs.
With a queue holding five entries it is the sixth and later connections that the kernel resets, not everything past the fifth. Comment only; the backlog value and the macOS skips are unchanged.
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.
selftests/test_load_engine.py::TestAutoRouting::test_small_uses_threadpoolandTestThreadpool::test_all_succeedfail reliably on a local macOS machine. Both drive 50 concurrent requests at the shared module-scopedmock_serverfixture and assertfailure_rate == 0.0; the observed rate varies per run (0.48-0.82), which is what makes it read as timing flake rather than one fixture-level defect. Which of the two fails, or whether both do, varies per run.The cause is the fixture, not the load engine.
_ThreadedHTTPServerinheritsrequest_queue_size = 5fromsocketserver.TCPServer, and that value is thelisten()backlog rather than any limit on concurrent work. The tests open 50-1000 connections faster thanserve_forevercan accept them, so everything past the fifth queued connection is reset by the kernel before it is ever accepted. Those resets are counted as request failures, so the assertion reads a failure rate the fixture produced. macOS is stricter about the ceiling than Linux, which is why it surfaced there and CI stayed green.The fix sets
request_queue_size = 128on the fixture's server class. Note this deliberately does not change the base class: the sketch in the issue moved it toThreadingHTTPServer, but that class is documented in the code as intentionally avoided, because a thread started per request can die under coverage'sthreading.settracehook and silently swallow the request. Making that switch would have reverted an earlier fix.Verification
Before, on macOS: 3 of 3 runs failed, e.g.
assert 0.62 == 0.0with 19 of 50 requests succeeding. After: 5 of 5 runs pass. Full suite is 1621 passed, 3 skipped. Ruff check and format clean.The macOS skips stay
The issue asked whether the raised backlog also makes the two
_skip_high_concurrency_on_macosskips removable, and asked that it be verified at higher concurrency rather than assumed. It was, and the answer is no. Driving the same fixture server with the samerun_load_testcalls the skipped tests make, at backlog 128: the 100-request and 1000-request cases were clean 3 of 3, buttest_large_uses_asyncat 200 requests still flaked 1 in 8 (failure rates 0.105 and 0.02) against its strict== 0.0assertion. The ephemeral port range is a genuinely distinct limit from the listen backlog, as the issue suspected. The skips are left in place and no test's assertion is loosened here.Closes #575
Closes #517