test_timeouts.py
This file
Path
tests/test_timeouts.py
49 lines · 1.4 KiB · Python
Last changed by
Add Client.stream() method. (#600)Tom Christiebefore adoption8d8ea8b
History of this fileTake it
1import pytest23from httpx import (4 Client,5 ConnectTimeout,6 PoolLimits,7 PoolTimeout,8 ReadTimeout,9 Timeout,10 WriteTimeout,11)121314async def test_read_timeout(server, backend):15 timeout = Timeout(read_timeout=1e-6)1617 async with Client(timeout=timeout, backend=backend) as client:18 with pytest.raises(ReadTimeout):19 await client.get(server.url.copy_with(path="/slow_response"))202122async def test_write_timeout(server, backend):23 timeout = Timeout(write_timeout=1e-6)2425 async with Client(timeout=timeout, backend=backend) as client:26 with pytest.raises(WriteTimeout):27 data = b"*" * 1024 * 1024 * 10028 await client.put(server.url.copy_with(path="/slow_response"), data=data)293031async def test_connect_timeout(server, backend):32 timeout = Timeout(connect_timeout=1e-6)3334 async with Client(timeout=timeout, backend=backend) as client:35 with pytest.raises(ConnectTimeout):36 # See https://stackoverflow.com/questions/100841/37 await client.get("http://10.255.255.1/")383940async def test_pool_timeout(server, backend):41 pool_limits = PoolLimits(hard_limit=1)42 timeout = Timeout(pool_timeout=1e-4)4344 async with Client(45 pool_limits=pool_limits, timeout=timeout, backend=backend46 ) as client:47 async with client.stream("GET", server.url):48 with pytest.raises(PoolTimeout):49 await client.get("http://localhost:8000/")