pytest wall time regressed from ~2min to ~20min (closes #469)#507
Merged
Conversation
Python's HTTPServer.serve_forever() defaults to poll_interval=0.5s, so every srv.shutdown() call blocks up to 0.5s waiting for the loop to notice the shutdown event. With ~40 tests using the server fixture this was adding ~17s of pure wait to the serial test run. Pass poll_interval=0.01 to serve_forever() in both the shared server fixture and TestSelfRestart._make_server. Serial suite: 27s → 11s.
4a31a87 to
387815d
Compare
The wfile socket is unbuffered (StreamRequestHandler.wbufsize=0), so _respond() delivers bytes to the client the moment they're written — before do_POST() finishes. Tests that asserted on work done after the ack (background _process_action threads, synchronous _self_restart) were papering over this race with time.sleep(0.2). Fix: add two injectable hooks to WebhookHandler: _fn_spawn_bg — spawns the background thread (was inline) _fn_after_do_post — no-op by default; called via try/finally in do_POST The autouse _restore_handler_fns fixture overrides _fn_after_do_post to set a threading.Event (_post_done) so _post_webhook can wait for do_POST to complete. The server fixture also overrides _fn_spawn_bg to capture the background thread in _bg_threads; _post_webhook joins it after the event fires. Result: all 28 time.sleep(0.2) calls removed; the 108 server tests now complete in ~1.5s serial (was ~24s) with deterministic synchronisation.
rhencke
approved these changes
Apr 14, 2026
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.
Fixes #469.
Shrink HTTPServer poll_interval in test fixtures so shutdown stops blocking 0.5s per test, and replace time.sleep(0.2) calls with deterministic thread joins. Together these cut ~21s of pure waste from the 27s serial run.
Work queue
Completed (2)