Skip to content

Extract the response delay and timeout simulation into a library #3415

Description

@adamtheturtle

MockVWS._wrap_callback in src/mock_vws/decorators.py and _make_respx_callback in src/mock_vws/_respx_mock_server/decorators.py simulate a slow server and raise the correct client-side timeout for both requests and httpx. Neither responses nor respx supports this, so anyone testing client timeout handling today either monkeypatches or runs a real slow server.

Getting it right needs knowledge which is not discoverable from the libraries' documentation:

  • responses attaches req_kwargs to PreparedRequest dynamically, so it is absent from the requests type stubs.
  • requests accepts the timeout as a (connect, read) tuple, and only the read leg is meaningful for a server which is slow to respond.
  • httpx puts the equivalent in request.extensions["timeout"].
  • Each needs a different exception raised: requests.exceptions.Timeout and httpx.ReadTimeout.

The injectable sleep_fn is also part of the value, because it lets callers control virtual time instead of really sleeping.

This built on #2884, #2919 and #2974. Closing this means the code moves to its own package and this repository depends on it.

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