@@ -30,7 +30,7 @@ async def test_connection_pool_with_keepalive():
30
30
)
31
31
32
32
async with httpcore .AsyncConnectionPool (
33
- network_backend = network_backend ,
33
+ network_backend = network_backend , max_keepalive_connections = 1
34
34
) as pool :
35
35
# Sending an intial request, which once complete will return to the pool, IDLE.
36
36
async with pool .stream ("GET" , "https://example.com/" ) as response :
@@ -79,28 +79,33 @@ async def test_connection_pool_with_keepalive():
79
79
)
80
80
81
81
# Sending a request to a different origin will not reuse the existing IDLE connection.
82
- async with pool .stream ("GET" , "http://example.com/" ) as response :
82
+ async with pool .stream ("GET" , "http://example.com/" ) as response_1 , pool .stream (
83
+ "GET" , "http://example.com/"
84
+ ) as response_2 :
83
85
info = [repr (c ) for c in pool .connections ]
84
86
assert info == [
85
87
"<AsyncHTTPConnection ['https://example.com:443', HTTP/1.1, IDLE, Request Count: 2]>" ,
86
88
"<AsyncHTTPConnection ['http://example.com:80', HTTP/1.1, ACTIVE, Request Count: 1]>" ,
89
+ "<AsyncHTTPConnection ['http://example.com:80', HTTP/1.1, ACTIVE, Request Count: 1]>" ,
87
90
]
88
91
assert (
89
92
repr (pool )
90
- == "<AsyncConnectionPool [Requests: 1 active, 0 queued | Connections: 1 active, 1 idle]>"
93
+ == "<AsyncConnectionPool [Requests: 2 active, 0 queued | Connections: 2 active, 1 idle]>"
91
94
)
92
- await response .aread ()
95
+ await response_1 .aread ()
96
+ await response_2 .aread ()
93
97
94
- assert response .status == 200
95
- assert response .content == b"Hello, world!"
98
+ assert response_1 .status == 200
99
+ assert response_1 .content == b"Hello, world!"
100
+ assert response_2 .status == 200
101
+ assert response_2 .content == b"Hello, world!"
96
102
info = [repr (c ) for c in pool .connections ]
97
103
assert info == [
98
- "<AsyncHTTPConnection ['https://example.com:443', HTTP/1.1, IDLE, Request Count: 2]>" ,
99
104
"<AsyncHTTPConnection ['http://example.com:80', HTTP/1.1, IDLE, Request Count: 1]>" ,
100
105
]
101
106
assert (
102
107
repr (pool )
103
- == "<AsyncConnectionPool [Requests: 0 active, 0 queued | Connections: 0 active, 2 idle]>"
108
+ == "<AsyncConnectionPool [Requests: 0 active, 0 queued | Connections: 0 active, 1 idle]>"
104
109
)
105
110
106
111
0 commit comments