test_timeouts.py
This file
Path
tests/test_timeouts.py
53 lines · 1.5 KiB · Python
Last changed by
100% test coverage (#71)Tom Christiebefore adoptionfc16d31
History of this fileTake it
1import pytest23from httpcore import (4 AsyncClient,5 ConnectTimeout,6 PoolLimits,7 PoolTimeout,8 ReadTimeout,9 WriteTimeout,10 TimeoutConfig,11)121314@pytest.mark.asyncio15async def test_read_timeout(server):16 timeout = TimeoutConfig(read_timeout=0.000001)1718 async with AsyncClient(timeout=timeout) as client:19 with pytest.raises(ReadTimeout):20 await client.get("http://127.0.0.1:8000/slow_response")212223@pytest.mark.asyncio24async def test_write_timeout(server):25 timeout = TimeoutConfig(write_timeout=0.000001)2627 async with AsyncClient(timeout=timeout) as client:28 with pytest.raises(WriteTimeout):29 data = b"*" * 1024 * 1024 * 10030 await client.put("http://127.0.0.1:8000/slow_response", data=data)313233@pytest.mark.asyncio34async def test_connect_timeout(server):35 timeout = TimeoutConfig(connect_timeout=0.000001)3637 async with AsyncClient(timeout=timeout) as client:38 with pytest.raises(ConnectTimeout):39 # See https://stackoverflow.com/questions/100841/40 await client.get("http://10.255.255.1/")414243@pytest.mark.asyncio44async def test_pool_timeout(server):45 pool_limits = PoolLimits(hard_limit=1, pool_timeout=0.000001)4647 async with AsyncClient(pool_limits=pool_limits) as client:48 response = await client.get("http://127.0.0.1:8000/", stream=True)4950 with pytest.raises(PoolTimeout):51 await client.get("http://localhost:8000/")5253 await response.read()