Skip to content
Myr

test_timeouts.py

This file

Path

tests/test_timeouts.py

35 lines · 1.1 KiB · Python

Last changed by

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

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

line 26why, one step back
26async def test_pool_timeout(server):

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 27why, one step back
27 limits = httpcore.PoolLimits(hard_limit=1, pool_timeout=0.0001)

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

line 28why, one step back
28

Merge pull request #23 from encode/adaptersTom Christiebefore adoption696c054

line 29why, one step back
29 async with httpcore.ConnectionPool(limits=limits) as http:

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

lines 30–35why, one step back
30 response = await http.request("GET", "http://127.0.0.1:8000/", stream=True)
3132 with pytest.raises(httpcore.PoolTimeout):33 await http.request("GET", "http://localhost:8000/")3435 await response.read()