Skip to content
Myr

test_timeouts.py

This file

Path

tests/test_timeouts.py

42 lines · 1.1 KiB · Python

Last changed by

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

History of this file

Take it

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

lines 1–2why, one step back
1import pytest
2

Truckin' onTom Christiebefore adoption6b60d95

line 3why, one step back
3from httpcore import (

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 4why, one step back
4 AsyncClient,

Truckin' onTom Christiebefore adoption6b60d95

lines 5–10why, one step back
5 ConnectTimeout,
6 PoolLimits,7 PoolTimeout,8 ReadTimeout,9 TimeoutConfig,10)

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

lines 11–14why, one step back
11
1213@pytest.mark.asyncio14async def test_read_timeout(server):

Truckin' onTom Christiebefore adoption6b60d95

line 15why, one step back
15 timeout = TimeoutConfig(read_timeout=0.0001)

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

line 16why, one step back
16

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 17why, one step back
17 async with AsyncClient(timeout=timeout) as client:

Truckin' onTom Christiebefore adoption6b60d95

lines 18–19why, one step back
18 with pytest.raises(ReadTimeout):
19 await client.get("http://127.0.0.1:8000/slow_response")

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

lines 20–22why, one step back
20
2122@pytest.mark.asyncio

Add ConnectTimeout testTom Christiebefore adoption74c9048

line 23why, one step back
23async def test_connect_timeout(server):

Truckin' onTom Christiebefore adoption6b60d95

line 24why, one step back
24 timeout = TimeoutConfig(connect_timeout=0.0001)

Add ConnectTimeout testTom Christiebefore adoption74c9048

line 25why, one step back
25

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 26why, one step back
26 async with AsyncClient(timeout=timeout) as client:

Truckin' onTom Christiebefore adoption6b60d95

line 27why, one step back
27 with pytest.raises(ConnectTimeout):

Add ConnectTimeout testTom Christiebefore adoption74c9048

line 28why, one step back
28 # See https://stackoverflow.com/questions/100841/

Truckin' onTom Christiebefore adoption6b60d95

line 29why, one step back
29 await client.get("http://10.255.255.1/")

Add ConnectTimeout testTom Christiebefore adoption74c9048

lines 30–32why, one step back
30
3132@pytest.mark.asyncio

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

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

Truckin' onTom Christiebefore adoption6b60d95

line 34why, one step back
34 pool_limits = PoolLimits(hard_limit=1, pool_timeout=0.0001)

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

line 35why, one step back
35

Merge pull request #58 from encode/sync-by-defaultTom Christiebefore adoptionb6c27f0

line 36why, one step back
36 async with AsyncClient(pool_limits=pool_limits) as client:

Truckin' onTom Christiebefore adoption6b60d95

line 37why, one step back
37 response = await client.get("http://127.0.0.1:8000/", stream=True)

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

line 38why, one step back
38

Truckin' onTom Christiebefore adoption6b60d95

lines 39–40why, one step back
39 with pytest.raises(PoolTimeout):
40 await client.get("http://localhost:8000/")

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

lines 41–42why, one step back
41
42 await response.read()