Skip to content
Myr

test_timeouts.py

This file

Path

tests/test_timeouts.py

60 lines · 1.8 KiB · Python

Last changed by

Fix bug when using client without timeouts in Python 3.6 (#383)Florimond Mancabefore adoptioncadb9a4

History of this file

Take it

1import pytest23from httpx import (4    AsyncClient,5    Client,6    ConnectTimeout,7    PoolLimits,8    PoolTimeout,9    ReadTimeout,10    TimeoutConfig,11    WriteTimeout,12)131415async def test_read_timeout(server, backend):16    timeout = TimeoutConfig(read_timeout=1e-6)1718    async with AsyncClient(timeout=timeout, backend=backend) as client:19        with pytest.raises(ReadTimeout):20            await client.get(server.url.copy_with(path="/slow_response"))212223async def test_write_timeout(server, backend):24    timeout = TimeoutConfig(write_timeout=1e-6)2526    async with AsyncClient(timeout=timeout, backend=backend) as client:27        with pytest.raises(WriteTimeout):28            data = b"*" * 1024 * 1024 * 10029            await client.put(server.url.copy_with(path="/slow_response"), data=data)303132async def test_connect_timeout(server, backend):33    timeout = TimeoutConfig(connect_timeout=1e-6)3435    async with AsyncClient(timeout=timeout, backend=backend) as client:36        with pytest.raises(ConnectTimeout):37            # See https://stackoverflow.com/questions/100841/38            await client.get("http://10.255.255.1/")394041async def test_pool_timeout(server, backend):42    pool_limits = PoolLimits(hard_limit=1, pool_timeout=1e-4)4344    async with AsyncClient(pool_limits=pool_limits, backend=backend) as client:45        response = await client.get(server.url, stream=True)4647        with pytest.raises(PoolTimeout):48            await client.get("http://localhost:8000/")4950        await response.read()515253def test_sync_infinite_timeout(server):54    """Regression test for a bug that occurred under Python 3.6.5556    See: https://github.com/encode/httpx/issues/38257    """58    no_timeout = TimeoutConfig()59    with Client(timeout=no_timeout) as client:60        client.get(server.url.copy_with(path="/slow_response/50"))