Skip to content
Myr

test_timeouts.py

This file

Path

tests/test_timeouts.py

42 lines · 1.1 KiB · Python

Last changed by

Truckin' onTom Christiebefore adoption6b60d95

History of this file

Take it

1import pytest23from httpcore import (4    Client,5    ConnectTimeout,6    PoolLimits,7    PoolTimeout,8    ReadTimeout,9    TimeoutConfig,10)111213@pytest.mark.asyncio14async def test_read_timeout(server):15    timeout = TimeoutConfig(read_timeout=0.0001)1617    async with Client(timeout=timeout) as client:18        with pytest.raises(ReadTimeout):19            await client.get("http://127.0.0.1:8000/slow_response")202122@pytest.mark.asyncio23async def test_connect_timeout(server):24    timeout = TimeoutConfig(connect_timeout=0.0001)2526    async with Client(timeout=timeout) as client:27        with pytest.raises(ConnectTimeout):28            # See https://stackoverflow.com/questions/100841/29            await client.get("http://10.255.255.1/")303132@pytest.mark.asyncio33async def test_pool_timeout(server):34    pool_limits = PoolLimits(hard_limit=1, pool_timeout=0.0001)3536    async with Client(pool_limits=pool_limits) as client:37        response = await client.get("http://127.0.0.1:8000/", stream=True)3839        with pytest.raises(PoolTimeout):40            await client.get("http://localhost:8000/")4142        await response.read()