Add injectable sleep_fn parameter to MockVWS#2920
Merged
adamtheturtle merged 1 commit intomainfrom Feb 15, 2026
Merged
Conversation
Enable deterministic test-time delay handling by allowing callers to inject a custom sleep strategy. This avoids the need for monkeypatching and enables virtual time control with libraries like freezegun. - Add sleep_fn parameter to MockVWS.__init__ with default time.sleep - Pass sleep_fn through to _wrap_callback for both timeout and delay paths - Add tests verifying injected sleep_fn is called on both success and timeout paths - Update changelog Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
06066d9 to
b3c1cc3
Compare
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.
Summary
Implements issue #2919 by adding an injectable
sleep_fnparameter toMockVWS. This allows callers to inject a custom delay strategy for testing timeout behavior without monkeypatching internals.Changes
sleep_fn: Callable[[float], None] = time.sleepparameter toMockVWS.__init___wrap_callbackfor both the timeout and success code pathsTest plan
✓ All 6 existing and new response delay tests pass
✓ Custom sleep function is called with correct delay value on success path
✓ Custom sleep function is called with effective timeout on timeout path
🤖 Generated with Claude Code
Note
Low Risk
Small, additive API change limited to test/mock timing behavior; primary risk is minor backward-compatibility/typing issues for callers constructing
MockVWS.Overview
MockVWSnow accepts an injectablesleep_fn(defaulting totime.sleep) and threads it through the response-delay wrapper so both the timeout and successful delay paths use the provided sleep strategy instead of hardcoded sleeping.Adds tests asserting the injected function is called with the configured delay or the effective timeout value, and documents the new parameter in
CHANGELOG.rst.Written by Cursor Bugbot for commit b3c1cc3. This will update automatically on new commits. Configure here.