Skip to content
Myr

test_timeouts.py

This file

Path

tests/test_timeouts.py

53 lines · 1.5 KiB · Python

Last changed by

Add test for write timeout error (#67)Yeray Diaz Diazbefore adoptionb8b3714

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–8why, one step back
5 ConnectTimeout,
6 PoolLimits,7 PoolTimeout,8 ReadTimeout,

Add test for write timeout error (#67)Yeray Diaz Diazbefore adoptionb8b3714

line 9why, one step back
9 WriteTimeout,

Truckin' onTom Christiebefore adoption6b60d95

lines 10–11why, one step back
10 TimeoutConfig,
11)

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

lines 12–15why, one step back
12
1314@pytest.mark.asyncio15async def test_read_timeout(server):

Truckin' onTom Christiebefore adoption6b60d95

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

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

line 17why, one step back
17

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

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

Truckin' onTom Christiebefore adoption6b60d95

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

Add test for write timeout error (#67)Yeray Diaz Diazbefore adoptionb8b3714

lines 21–30why, one step back
21
2223@pytest.mark.asyncio24async def test_write_timeout(server):25 timeout = TimeoutConfig(write_timeout=0.0001)2627 async with AsyncClient(timeout=timeout) as client:28 with pytest.raises(WriteTimeout):29 data = b"*" * 1024 * 1024 * 1030 await client.put("http://127.0.0.1:8000/slow_response", data=data)

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

lines 31–33why, one step back
31
3233@pytest.mark.asyncio

Add ConnectTimeout testTom Christiebefore adoption74c9048

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

Truckin' onTom Christiebefore adoption6b60d95

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

Add ConnectTimeout testTom Christiebefore adoption74c9048

line 36why, one step back
36

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

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

Truckin' onTom Christiebefore adoption6b60d95

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

Add ConnectTimeout testTom Christiebefore adoption74c9048

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

Truckin' onTom Christiebefore adoption6b60d95

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

Add ConnectTimeout testTom Christiebefore adoption74c9048

lines 41–43why, one step back
41
4243@pytest.mark.asyncio

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

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

Truckin' onTom Christiebefore adoption6b60d95

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

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

line 46why, one step back
46

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

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

Truckin' onTom Christiebefore adoption6b60d95

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

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

line 49why, one step back
49

Truckin' onTom Christiebefore adoption6b60d95

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

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

lines 52–53why, one step back
52
53 await response.read()