test_connection_pools.py
This file
Path
tests/dispatch/test_connection_pools.py
182 lines · 6.2 KiB · Python
Last changed by
Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
History of this fileTake it
The walk stopped after 200 commits: lines older than b46d9ea point at it.
Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
line 1why, one step back1import httpxTighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
line 2why, one step back2from httpx.dispatch.connection_pool import ConnectionPoolInstall package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 3–4why, one step back34Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 5why, one step back5async def test_keepalive_connections(server, backend):Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 6–8why, one step back6 """7 Connections should default to staying in a keep-alive state.8 """Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
line 9why, one step back9 async with ConnectionPool(backend=backend) as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 10why, one step back10 response = await http.request("GET", server.url)Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 11–14why, one step back11 await response.read()12 assert len(http.active_connections) == 013 assert len(http.keepalive_connections) == 114Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 15why, one step back15 response = await http.request("GET", server.url)Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 16–20why, one step back16 await response.read()17 assert len(http.active_connections) == 018 assert len(http.keepalive_connections) == 11920Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 21why, one step back21async def test_differing_connection_keys(server, backend):Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 22–24why, one step back22 """23 Connections to differing connection keys should result in multiple connections.24 """Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
line 25why, one step back25 async with ConnectionPool(backend=backend) as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 26why, one step back26 response = await http.request("GET", server.url)Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 27–36why, one step back27 await response.read()28 assert len(http.active_connections) == 029 assert len(http.keepalive_connections) == 13031 response = await http.request("GET", "http://localhost:8000/")32 await response.read()33 assert len(http.active_connections) == 034 assert len(http.keepalive_connections) == 23536Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 37why, one step back37async def test_soft_limit(server, backend):Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 38–42why, one step back38 """39 The soft_limit config should limit the maximum number of keep-alive connections.40 """41 pool_limits = httpx.PoolLimits(soft_limit=1)42Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
line 43why, one step back43 async with ConnectionPool(pool_limits=pool_limits, backend=backend) as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 44why, one step back44 response = await http.request("GET", server.url)Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 45–54why, one step back45 await response.read()46 assert len(http.active_connections) == 047 assert len(http.keepalive_connections) == 14849 response = await http.request("GET", "http://localhost:8000/")50 await response.read()51 assert len(http.active_connections) == 052 assert len(http.keepalive_connections) == 15354Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 55why, one step back55async def test_streaming_response_holds_connection(server, backend):Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 56–58why, one step back56 """57 A streaming request should hold the connection open until the response is read.58 """Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
line 59why, one step back59 async with ConnectionPool(backend=backend) as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 60why, one step back60 response = await http.request("GET", server.url)Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 61–69why, one step back61 assert len(http.active_connections) == 162 assert len(http.keepalive_connections) == 06364 await response.read()6566 assert len(http.active_connections) == 067 assert len(http.keepalive_connections) == 16869Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 70why, one step back70async def test_multiple_concurrent_connections(server, backend):Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 71–73why, one step back71 """72 Multiple conncurrent requests should open multiple conncurrent connections.73 """Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
line 74why, one step back74 async with ConnectionPool(backend=backend) as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 75why, one step back75 response_a = await http.request("GET", server.url)Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 76–78why, one step back76 assert len(http.active_connections) == 177 assert len(http.keepalive_connections) == 078Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 79why, one step back79 response_b = await http.request("GET", server.url)Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 80–91why, one step back80 assert len(http.active_connections) == 281 assert len(http.keepalive_connections) == 08283 await response_b.read()84 assert len(http.active_connections) == 185 assert len(http.keepalive_connections) == 18687 await response_a.read()88 assert len(http.active_connections) == 089 assert len(http.keepalive_connections) == 29091Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 92why, one step back92async def test_close_connections(server, backend):Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 93–96why, one step back93 """94 Using a `Connection: close` header should close the connection.95 """96 headers = [(b"connection", b"close")]Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
line 97why, one step back97 async with ConnectionPool(backend=backend) as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 98why, one step back98 response = await http.request("GET", server.url, headers=headers)Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 99–103why, one step back99 await response.read()100 assert len(http.active_connections) == 0101 assert len(http.keepalive_connections) == 0102103Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 104why, one step back104async def test_standard_response_close(server, backend):Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 105–107why, one step back105 """106 A standard close should keep the connection open.107 """Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
line 108why, one step back108 async with ConnectionPool(backend=backend) as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 109why, one step back109 response = await http.request("GET", server.url)Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 110–115why, one step back110 await response.read()111 await response.close()112 assert len(http.active_connections) == 0113 assert len(http.keepalive_connections) == 1114115Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 116why, one step back116async def test_premature_response_close(server, backend):Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 117–119why, one step back117 """118 A premature close should close the connection.119 """Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
line 120why, one step back120 async with ConnectionPool(backend=backend) as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 121why, one step back121 response = await http.request("GET", server.url)Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 122–126why, one step back122 await response.close()123 assert len(http.active_connections) == 0124 assert len(http.keepalive_connections) == 0125126Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
lines 127–129why, one step back127async def test_keepalive_connection_closed_by_server_is_reestablished(128 server, restart, backend129):Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 130–133why, one step back130 """131 Upon keep-alive connection closed by remote a new connection132 should be reestablished.133 """Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
line 134why, one step back134 async with ConnectionPool(backend=backend) as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 135why, one step back135 response = await http.request("GET", server.url)Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 136–137why, one step back136 await response.read()137Serve test server in thread (#292)Florimond Mancabefore adoption994403b
line 138why, one step back138 # Shutdown the server to close the keep-alive connectionParametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 139why, one step back139 await restart(server)Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
line 140why, one step back140Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 141why, one step back141 response = await http.request("GET", server.url)Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 142–146why, one step back142 await response.read()143 assert len(http.active_connections) == 0144 assert len(http.keepalive_connections) == 1145146Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
lines 147–149why, one step back147async def test_keepalive_http2_connection_closed_by_server_is_reestablished(148 server, restart, backend149):Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 150–153why, one step back150 """151 Upon keep-alive connection closed by remote a new connection152 should be reestablished.153 """Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
line 154why, one step back154 async with ConnectionPool(backend=backend) as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 155why, one step back155 response = await http.request("GET", server.url)Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 156–157why, one step back156 await response.read()157Serve test server in thread (#292)Florimond Mancabefore adoption994403b
line 158why, one step back158 # Shutdown the server to close the keep-alive connectionParametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 159why, one step back159 await restart(server)Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
line 160why, one step back160Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 161why, one step back161 response = await http.request("GET", server.url)Install package locally in test-requirements.txt (#231)Florimond Mancabefore adoptionb46d9ea
lines 162–164why, one step back162 await response.read()163 assert len(http.active_connections) == 0164 assert len(http.keepalive_connections) == 1Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a
lines 165–166why, one step back165166Parametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 167why, one step back167async def test_connection_closed_free_semaphore_on_acquire(server, restart, backend):Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a
lines 168–171why, one step back168 """169 Verify that max_connections semaphore is released170 properly on a disconnected connection.171 """Tighten up top-level API to only expose public API (#608)Tom Christiebefore adoptiond15dc0b
line 172why, one step back172 async with ConnectionPool(Add trio concurrency backend (#276)Florimond Mancabefore adoption08355c6
lines 173–174why, one step back173 pool_limits=httpx.PoolLimits(hard_limit=1), backend=backend174 ) as http:Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 175why, one step back175 response = await http.request("GET", server.url)Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a
lines 176–178why, one step back176 await response.read()177178 # Close the connection so we're forced to recycle itParametrize tests with concurrency backend (#273)Florimond Mancabefore adoption3674058
line 179why, one step back179 await restart(server)Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a
line 180why, one step back180Add server.url property in tests (#300)Bakhtiyor Ruzievbefore adoptione34d280
line 181why, one step back181 response = await http.request("GET", server.url)Release semaphore if connection is dropped (#230)Ordanis Sanchezbefore adoptiona960a2a
line 182why, one step back182 assert response.status_code == 200