Skip to content
Myr

test_timeouts.py

This file

Path

tests/test_timeouts.py

36 lines · 1.2 KiB · Python

Last changed by

Add ConnectTimeout testTom Christiebefore adoption74c9048

History of this file

Take it

Merge pull request #7 from encode/timeout-testsTom Christiebefore adoption34c03d7

lines 1–15why, one step back
1import pytest
23import httpcore456@pytest.mark.asyncio7async def test_read_timeout(server):8 timeout = httpcore.TimeoutConfig(read_timeout=0.0001)910 async with httpcore.ConnectionPool(timeout=timeout) as http:11 with pytest.raises(httpcore.ReadTimeout):12 await http.request("GET", "http://127.0.0.1:8000/slow_response")131415@pytest.mark.asyncio

Add ConnectTimeout testTom Christiebefore adoption74c9048

lines 16–25why, one step back
16async def test_connect_timeout(server):
17 timeout = httpcore.TimeoutConfig(connect_timeout=0.0001)1819 async with httpcore.ConnectionPool(timeout=timeout) as http:20 with pytest.raises(httpcore.ConnectTimeout):21 # See https://stackoverflow.com/questions/100841/22 await http.request("GET", "http://10.255.255.1/")232425@pytest.mark.asyncio

Merge pull request #7 from encode/timeout-testsTom Christiebefore adoption34c03d7

lines 26–36why, one step back
26async def test_pool_timeout(server):
27 timeout = httpcore.TimeoutConfig(pool_timeout=0.0001)28 limits = httpcore.PoolLimits(hard_limit=1)2930 async with httpcore.ConnectionPool(timeout=timeout, limits=limits) as http:31 response = await http.request("GET", "http://127.0.0.1:8000/", stream=True)3233 with pytest.raises(httpcore.PoolTimeout):34 await http.request("GET", "http://localhost:8000/")3536 await response.read()