Skip to content

Add response delay simulation for testing request timeouts #2884

@adamtheturtle

Description

@adamtheturtle

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:

  1. Short timeouts raise requests.exceptions.Timeout when the server is slow
  2. 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions