test_timeouts.py
This file
Path
tests/test_timeouts.py
41 lines · 1.4 KiB · Python
Last changed by
Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
History of this fileTake it
1import pytest23import httpx456async def test_read_timeout(server, backend):7 timeout = httpx.Timeout(read_timeout=1e-6)89 async with httpx.Client(timeout=timeout, backend=backend) as client:10 with pytest.raises(httpx.ReadTimeout):11 await client.get(server.url.copy_with(path="/slow_response"))121314async def test_write_timeout(server, backend):15 timeout = httpx.Timeout(write_timeout=1e-6)1617 async with httpx.Client(timeout=timeout, backend=backend) as client:18 with pytest.raises(httpx.WriteTimeout):19 data = b"*" * 1024 * 1024 * 10020 await client.put(server.url.copy_with(path="/slow_response"), data=data)212223async def test_connect_timeout(server, backend):24 timeout = httpx.Timeout(connect_timeout=1e-6)2526 async with httpx.Client(timeout=timeout, backend=backend) as client:27 with pytest.raises(httpx.ConnectTimeout):28 # See https://stackoverflow.com/questions/100841/29 await client.get("http://10.255.255.1/")303132async def test_pool_timeout(server, backend):33 pool_limits = httpx.PoolLimits(hard_limit=1)34 timeout = httpx.Timeout(pool_timeout=1e-4)3536 async with httpx.Client(37 pool_limits=pool_limits, timeout=timeout, backend=backend38 ) as client:39 async with client.stream("GET", server.url):40 with pytest.raises(httpx.PoolTimeout):41 await client.get("http://localhost:8000/")