mirror of
https://github.com/BerriAI/litellm.git
synced 2026-11-05 07:37:50 +00:00
test(aiohttp): cover bytes already read before a dropped connection
Co-Authored-By: Devin AI <158243242+devin-ai-integration[bot]@users.noreply.github.com>
This commit is contained in:
parent
d54b3dc4be
commit
96d63d52bd
1 changed files with 22 additions and 0 deletions
|
|
@ -162,6 +162,28 @@ async def test_bytes_buffered_before_a_dropped_connection_are_yielded_before_the
|
|||
assert mock_response.closed is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_bytes_already_read_before_a_dropped_connection_are_not_yielded_again():
|
||||
loop: Final = asyncio.get_running_loop()
|
||||
content: Final = aiohttp.StreamReader(aiohttp.base_protocol.BaseProtocol(loop), 2**16, loop=loop)
|
||||
content.feed_data(b"event: message_start\n\n")
|
||||
content.feed_data(b"event: ping\n\n")
|
||||
assert await content.read(7) == b"event: "
|
||||
content.set_exception(aiohttp.ClientPayloadError("Response payload is not completed"))
|
||||
mock_response: Final = MockAiohttpResponse()
|
||||
mock_response.content = content
|
||||
received: Final[list[bytes]] = []
|
||||
|
||||
async def _drain() -> None:
|
||||
async for chunk in AiohttpResponseStream(mock_response): # pyright: ignore[reportArgumentType] # mock response
|
||||
received.append(chunk)
|
||||
|
||||
with pytest.raises(httpx.ReadError):
|
||||
await _drain()
|
||||
|
||||
assert received == [b"message_start\n\nevent: ping\n\n"]
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_client_payload_error_before_first_chunk_raises_read_error():
|
||||
"""A connection reset before any body byte must surface, not yield an empty 200 body"""
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue