Repository navigation
Conversation
kuhe
force-pushed
the
kuhe/test/http_mock
branch
10 times, most recently
from
November 12, 2026 15:46
de7e26e to
05a2513
Compare
kuhe
force-pushed
the
kuhe/test/http_mock
branch
from
November 12, 2026 17:41
05a2513 to
4e0e3be
Compare
kuhe
marked this pull request as ready for review
November 12, 2026 19:16
| request_config: HTTPRequestConfiguration | None = None, | ||
| ) -> HTTPResponse: | ||
| captured = copy(request) | ||
| captured.body = await read_streaming_blob_async(request.body) |
Contributor
There was a problem hiding this comment.
This hangs for event-stream calls.
For event streams, the request body stays open while events are sent. This line waits for it to close before responding. But AsyncDuplexEventStream.close() (called by async with) waits for the response before closing it, and so does a test that calls await_output() first.
The mock wants to see the whole request first, then respond. But in these streams the test (or close()) wants the response first, then finishes the request. Each order makes sense alone; together they wait on each other forever.
async with await client.duplex_stream(DuplexStreamInput()) as stream:
await stream.input_stream.send(event)
# never returnsSuggested fix: for stream bodies, respond right away and read the body in the background:
body = request.body
if isinstance(body, AsyncIterable) or inspect.iscoroutinefunction(
getattr(body, "read", None)
):
captured.body = b""
async def drain() -> None:
captured.body = await read_streaming_blob_async(body)
self._drains.append(asyncio.create_task(drain()))
else:
captured.body = await read_streaming_blob_async(body)
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.
This PR creates a test API for HTTP mocking, which uses the existing capturing transports (smithy-http.test), but adds sugar for declaring what parts of the request/response you're interested in asserting on.
Reviewers
Other than the sample usage below, see new tests in this PR's diff using the mock API by filtering by
/functional/.