Summary
Add support for simulating slow HTTP responses to enable testing of request timeout handling in client code.
Proposed Interface
from mock_vws import MockVWS
# Simulate 0.5 second delay on all responses
with MockVWS(response_delay_seconds=0.5) as mock:
database = VuforiaDatabase()
mock.add_database(database=database)
# Client with short timeout will fail
vws_client = VWS(
server_access_key=database.server_access_key,
server_secret_key=database.server_secret_key,
request_timeout_seconds=0.1,
)
vws_client.list_targets() # Raises requests.exceptions.Timeout
Use Case
vws-python recently added configurable request_timeout_seconds to VWS and CloudRecoService. To properly test this, we need to verify that:
- Short timeouts raise
requests.exceptions.Timeout when the server is slow
- Longer timeouts allow slow responses to complete
Currently, we're using unittest.mock.patch to intercept requests.request and artificially raise Timeout, but this:
- Doesn't test the real timeout mechanism
- Requires ugly type annotation hacks
- Tests at the wrong layer
With response_delay_seconds, we could test the actual integration end-to-end.
Expected Behavior
response_delay_seconds defaults to 0 (no delay)
- When set, all mock responses are delayed by the specified number of seconds
- The delay happens at the HTTP response level so that
requests' native timeout handling triggers naturally
Summary
Add support for simulating slow HTTP responses to enable testing of request timeout handling in client code.
Proposed Interface
Use Case
vws-python recently added configurable
request_timeout_secondstoVWSandCloudRecoService. To properly test this, we need to verify that:requests.exceptions.Timeoutwhen the server is slowCurrently, we're using
unittest.mock.patchto interceptrequests.requestand artificially raiseTimeout, but this:With
response_delay_seconds, we could test the actual integration end-to-end.Expected Behavior
response_delay_secondsdefaults to0(no delay)requests' native timeout handling triggers naturally