Skip to content
Myr

test_timeouts.py

This file

Path

tests/test_timeouts.py

49 lines · 1.5 KiB · Python

Last changed by

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

History of this file

Take it

1import pytest23from httpx import (4    AsyncClient,5    ConnectTimeout,6    PoolLimits,7    PoolTimeout,8    ReadTimeout,9    TimeoutConfig,10    WriteTimeout,11)121314async def test_read_timeout(server, backend):15    timeout = TimeoutConfig(read_timeout=1e-6)1617    async with AsyncClient(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 = TimeoutConfig(write_timeout=1e-6)2425    async with AsyncClient(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 = TimeoutConfig(connect_timeout=1e-6)3334    async with AsyncClient(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, pool_timeout=1e-6)4243    async with AsyncClient(pool_limits=pool_limits, backend=backend) as client:44        response = await client.get(server.url, stream=True)4546        with pytest.raises(PoolTimeout):47            await client.get("http://localhost:8000/")4849        await response.read()