test_timeouts.py
This file
Path
tests/test_timeouts.py
43 lines · 1.5 KiB · Python
Last changed by
Replace remaining occurrences of dispatch with transport (#1010)Josep Cugatbefore adoption89a8100
History of this fileTake it
1import pytest23import httpx456@pytest.mark.usefixtures("async_environment")7async def test_read_timeout(server):8 timeout = httpx.Timeout(read_timeout=1e-6)910 async with httpx.AsyncClient(timeout=timeout) as client:11 with pytest.raises(httpx.ReadTimeout):12 await client.get(server.url.copy_with(path="/slow_response"))131415@pytest.mark.usefixtures("async_environment")16async def test_write_timeout(server):17 timeout = httpx.Timeout(write_timeout=1e-6)1819 async with httpx.AsyncClient(timeout=timeout) as client:20 with pytest.raises(httpx.WriteTimeout):21 data = b"*" * 1024 * 1024 * 10022 await client.put(server.url.copy_with(path="/slow_response"), data=data)232425@pytest.mark.usefixtures("async_environment")26async def test_connect_timeout(server):27 timeout = httpx.Timeout(connect_timeout=1e-6)2829 async with httpx.AsyncClient(timeout=timeout) as client:30 with pytest.raises(httpx.ConnectTimeout):31 # See https://stackoverflow.com/questions/100841/32 await client.get("http://10.255.255.1/")333435@pytest.mark.usefixtures("async_environment")36async def test_pool_timeout(server):37 pool_limits = httpx.PoolLimits(max_connections=1)38 timeout = httpx.Timeout(pool_timeout=1e-4)3940 async with httpx.AsyncClient(pool_limits=pool_limits, timeout=timeout) as client:41 async with client.stream("GET", server.url):42 with pytest.raises(httpx.PoolTimeout):43 await client.get("http://localhost:8000/")