Skip to content
Myr

test_connection_pools.py

This file

Path

tests/dispatch/test_connection_pools.py

179 lines · 6.2 KiB · Python

Last changed by

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

History of this file

Take it

The walk stopped after 200 commits: lines older than 5f8000f point at it.

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 1why, one step back
1import httpx

Updating docstringsTom Christiebefore adoption5f8000f

lines 2–3why, one step back
2
3

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 4why, one step back
4async def test_keepalive_connections(server, backend):

Updating docstringsTom Christiebefore adoption5f8000f

lines 5–7why, one step back
5 """
6 Connections should default to staying in a keep-alive state.7 """

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 8why, one step back
8 async with httpx.ConnectionPool(backend=backend) as http:

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

line 9why, one step back
9 response = await http.request("GET", server.url)

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 10why, one step back
10 await response.read()

Updating docstringsTom Christiebefore adoption5f8000f

lines 11–13why, one step back
11 assert len(http.active_connections) == 0
12 assert len(http.keepalive_connections) == 113

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

line 14why, one step back
14 response = await http.request("GET", server.url)

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 15why, one step back
15 await response.read()

Updating docstringsTom Christiebefore adoption5f8000f

lines 16–19why, one step back
16 assert len(http.active_connections) == 0
17 assert len(http.keepalive_connections) == 11819

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 20why, one step back
20async def test_differing_connection_keys(server, backend):

Updating docstringsTom Christiebefore adoption5f8000f

line 21why, one step back
21 """

Fix typos in docstringsSaugat Pachhaibefore adoption3451028

line 22why, one step back
22 Connections to differing connection keys should result in multiple connections.

Updating docstringsTom Christiebefore adoption5f8000f

line 23why, one step back
23 """

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 24why, one step back
24 async with httpx.ConnectionPool(backend=backend) as http:

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

line 25why, one step back
25 response = await http.request("GET", server.url)

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 26why, one step back
26 await response.read()

Updating docstringsTom Christiebefore adoption5f8000f

lines 27–30why, one step back
27 assert len(http.active_connections) == 0
28 assert len(http.keepalive_connections) == 12930 response = await http.request("GET", "http://localhost:8000/")

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 31why, one step back
31 await response.read()

Updating docstringsTom Christiebefore adoption5f8000f

lines 32–35why, one step back
32 assert len(http.active_connections) == 0
33 assert len(http.keepalive_connections) == 23435

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 36why, one step back
36async def test_soft_limit(server, backend):

Updating docstringsTom Christiebefore adoption5f8000f

lines 37–39why, one step back
37 """
38 The soft_limit config should limit the maximum number of keep-alive connections.39 """

Renaming -> httpx (#129)Tom Christiebefore adoption2d09d5b

line 40why, one step back
40 pool_limits = httpx.PoolLimits(soft_limit=1)

Updating docstringsTom Christiebefore adoption5f8000f

line 41why, one step back
41

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 42why, one step back
42 async with httpx.ConnectionPool(pool_limits=pool_limits, backend=backend) as http:

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

line 43why, one step back
43 response = await http.request("GET", server.url)

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 44why, one step back
44 await response.read()

Updating docstringsTom Christiebefore adoption5f8000f

lines 45–48why, one step back
45 assert len(http.active_connections) == 0
46 assert len(http.keepalive_connections) == 14748 response = await http.request("GET", "http://localhost:8000/")

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 49why, one step back
49 await response.read()

Updating docstringsTom Christiebefore adoption5f8000f

lines 50–53why, one step back
50 assert len(http.active_connections) == 0
51 assert len(http.keepalive_connections) == 15253

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 54why, one step back
54async def test_streaming_response_holds_connection(server, backend):

Updating docstringsTom Christiebefore adoption5f8000f

lines 55–57why, one step back
55 """
56 A streaming request should hold the connection open until the response is read.57 """

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 58why, one step back
58 async with httpx.ConnectionPool(backend=backend) as http:

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

line 59why, one step back
59 response = await http.request("GET", server.url)

Updating docstringsTom Christiebefore adoption5f8000f

lines 60–68why, one step back
60 assert len(http.active_connections) == 1
61 assert len(http.keepalive_connections) == 06263 await response.read()6465 assert len(http.active_connections) == 066 assert len(http.keepalive_connections) == 16768

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 69why, one step back
69async def test_multiple_concurrent_connections(server, backend):

Updating docstringsTom Christiebefore adoption5f8000f

lines 70–72why, one step back
70 """
71 Multiple conncurrent requests should open multiple conncurrent connections.72 """

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 73why, one step back
73 async with httpx.ConnectionPool(backend=backend) as http:

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

line 74why, one step back
74 response_a = await http.request("GET", server.url)

Updating docstringsTom Christiebefore adoption5f8000f

lines 75–77why, one step back
75 assert len(http.active_connections) == 1
76 assert len(http.keepalive_connections) == 077

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

line 78why, one step back
78 response_b = await http.request("GET", server.url)

Updating docstringsTom Christiebefore adoption5f8000f

lines 79–90why, one step back
79 assert len(http.active_connections) == 2
80 assert len(http.keepalive_connections) == 08182 await response_b.read()83 assert len(http.active_connections) == 184 assert len(http.keepalive_connections) == 18586 await response_a.read()87 assert len(http.active_connections) == 088 assert len(http.keepalive_connections) == 28990

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 91why, one step back
91async def test_close_connections(server, backend):

Updating docstringsTom Christiebefore adoption5f8000f

lines 92–95why, one step back
92 """
93 Using a `Connection: close` header should close the connection.94 """95 headers = [(b"connection", b"close")]

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 96why, one step back
96 async with httpx.ConnectionPool(backend=backend) as http:

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

line 97why, one step back
97 response = await http.request("GET", server.url, headers=headers)

Sync or Async dispatch (#83)Tom Christiebefore adoption0cbf3c7

line 98why, one step back
98 await response.read()

Updating docstringsTom Christiebefore adoption5f8000f

lines 99–102why, one step back
99 assert len(http.active_connections) == 0
100 assert len(http.keepalive_connections) == 0101102

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 103why, one step back
103async def test_standard_response_close(server, backend):

Updating docstringsTom Christiebefore adoption5f8000f

lines 104–106why, one step back
104 """
105 A standard close should keep the connection open.106 """

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 107why, one step back
107 async with httpx.ConnectionPool(backend=backend) as http:

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

line 108why, one step back
108 response = await http.request("GET", server.url)

Updating docstringsTom Christiebefore adoption5f8000f

lines 109–114why, one step back
109 await response.read()
110 await response.close()111 assert len(http.active_connections) == 0112 assert len(http.keepalive_connections) == 1113114

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 115why, one step back
115async def test_premature_response_close(server, backend):

Updating docstringsTom Christiebefore adoption5f8000f

lines 116–118why, one step back
116 """
117 A premature close should close the connection.118 """

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 119why, one step back
119 async with httpx.ConnectionPool(backend=backend) as http:

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

line 120why, one step back
120 response = await http.request("GET", server.url)

Updating docstringsTom Christiebefore adoption5f8000f

lines 121–123why, one step back
121 await response.close()
122 assert len(http.active_connections) == 0123 assert len(http.keepalive_connections) == 0

Check disconnections on connection reacquiry (#145)Tom Christiebefore adoptionec365c0

lines 124–125why, one step back
124
125

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

lines 126–128why, one step back
126async def test_keepalive_connection_closed_by_server_is_reestablished(
127 server, restart, backend128):

Check disconnections on connection reacquiry (#145)Tom Christiebefore adoptionec365c0

line 129why, one step back
129 """

Add additional flake8 plugins (#157)Can Sarıgölbefore adoption7e9110b

lines 130–131why, one step back
130 Upon keep-alive connection closed by remote a new connection
131 should be reestablished.

Check disconnections on connection reacquiry (#145)Tom Christiebefore adoptionec365c0

line 132why, one step back
132 """

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 133why, one step back
133 async with httpx.ConnectionPool(backend=backend) as http:

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

line 134why, one step back
134 response = await http.request("GET", server.url)

Check disconnections on connection reacquiry (#145)Tom Christiebefore adoptionec365c0

lines 135–136why, one step back
135 await response.read()
136

Serve test server in thread (#292)Florimond Mancabefore adoption994403b

line 137why, one step back
137 # Shutdown the server to close the keep-alive connection

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 138why, one step back
138 await restart(server)

Check disconnections on connection reacquiry (#145)Tom Christiebefore adoptionec365c0

line 139why, one step back
139

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

line 140why, one step back
140 response = await http.request("GET", server.url)

Check disconnections on connection reacquiry (#145)Tom Christiebefore adoptionec365c0

lines 141–145why, one step back
141 await response.read()
142 assert len(http.active_connections) == 0143 assert len(http.keepalive_connections) == 1144145

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

lines 146–148why, one step back
146async def test_keepalive_http2_connection_closed_by_server_is_reestablished(
147 server, restart, backend148):

Check disconnections on connection reacquiry (#145)Tom Christiebefore adoptionec365c0

line 149why, one step back
149 """

Add additional flake8 plugins (#157)Can Sarıgölbefore adoption7e9110b

lines 150–151why, one step back
150 Upon keep-alive connection closed by remote a new connection
151 should be reestablished.

Check disconnections on connection reacquiry (#145)Tom Christiebefore adoptionec365c0

line 152why, one step back
152 """

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 153why, one step back
153 async with httpx.ConnectionPool(backend=backend) as http:

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

line 154why, one step back
154 response = await http.request("GET", server.url)

Check disconnections on connection reacquiry (#145)Tom Christiebefore adoptionec365c0

lines 155–156why, one step back
155 await response.read()
156

Serve test server in thread (#292)Florimond Mancabefore adoption994403b

line 157why, one step back
157 # Shutdown the server to close the keep-alive connection

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 158why, one step back
158 await restart(server)

Check disconnections on connection reacquiry (#145)Tom Christiebefore adoptionec365c0

line 159why, one step back
159

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

line 160why, one step back
160 response = await http.request("GET", server.url)

Check disconnections on connection reacquiry (#145)Tom Christiebefore adoptionec365c0

lines 161–163why, one step back
161 await response.read()
162 assert len(http.active_connections) == 0163 assert len(http.keepalive_connections) == 1

Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a

lines 164–165why, one step back
164
165

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 166why, one step back
166async def test_connection_closed_free_semaphore_on_acquire(server, restart, backend):

Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a

lines 167–171why, one step back
167 """
168 Verify that max_connections semaphore is released169 properly on a disconnected connection.170 """171 async with httpx.ConnectionPool(pool_limits=httpx.PoolLimits(hard_limit=1)) as http:

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

line 172why, one step back
172 response = await http.request("GET", server.url)

Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a

lines 173–175why, one step back
173 await response.read()
174175 # Close the connection so we're forced to recycle it

Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058

line 176why, one step back
176 await restart(server)

Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a

line 177why, one step back
177

Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280

line 178why, one step back
178 response = await http.request("GET", server.url)

Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a

line 179why, one step back
179 assert response.status_code == 200