Skip to content

Commit 4e3e596

Browse files
committed
Add test for remote max streams update
1 parent ea68566 commit 4e3e596

File tree

2 files changed

+74
-0
lines changed

2 files changed

+74
-0
lines changed

tests/_async/test_http2.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,40 @@ async def test_http2_request_to_incorrect_origin():
294294
async with AsyncHTTP2Connection(origin=origin, stream=stream) as conn:
295295
with pytest.raises(RuntimeError):
296296
await conn.request("GET", "https://other.com/")
297+
298+
299+
@pytest.mark.anyio
300+
async def test_http2_remote_max_streams_update():
301+
"""
302+
If the remote server updates the maximum concurrent streams value, we should
303+
be adjusting how many streams we will allow.
304+
"""
305+
origin = Origin(b"https", b"example.com", 443)
306+
stream = AsyncMockStream(
307+
[
308+
hyperframe.frame.SettingsFrame(
309+
settings={hyperframe.frame.SettingsFrame.MAX_CONCURRENT_STREAMS: 1000}
310+
).serialize(),
311+
hyperframe.frame.HeadersFrame(
312+
stream_id=1,
313+
data=hpack.Encoder().encode(
314+
[
315+
(b":status", b"200"),
316+
(b"content-type", b"plain/text"),
317+
]
318+
),
319+
flags=["END_HEADERS"],
320+
).serialize(),
321+
hyperframe.frame.DataFrame(
322+
stream_id=1, data=b"Hello, world!", flags=["END_STREAM"]
323+
).serialize(),
324+
]
325+
)
326+
async with AsyncHTTP2Connection(origin=origin, stream=stream) as conn:
327+
async with conn.stream("GET", "https://example.com/") as response:
328+
await response.aread()
329+
assert conn._h2_state.remote_settings.max_concurrent_streams == 1000
330+
assert conn._max_streams == min(
331+
conn._h2_state.remote_settings.max_concurrent_streams,
332+
conn._h2_state.local_settings.max_concurrent_streams,
333+
)

tests/_sync/test_http2.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,3 +294,40 @@ def test_http2_request_to_incorrect_origin():
294294
with HTTP2Connection(origin=origin, stream=stream) as conn:
295295
with pytest.raises(RuntimeError):
296296
conn.request("GET", "https://other.com/")
297+
298+
299+
300+
def test_http2_remote_max_streams_update():
301+
"""
302+
If the remote server updates the maximum concurrent streams value, we should
303+
be adjusting how many streams we will allow.
304+
"""
305+
origin = Origin(b"https", b"example.com", 443)
306+
stream = MockStream(
307+
[
308+
hyperframe.frame.SettingsFrame(
309+
settings={hyperframe.frame.SettingsFrame.MAX_CONCURRENT_STREAMS: 1000}
310+
).serialize(),
311+
hyperframe.frame.HeadersFrame(
312+
stream_id=1,
313+
data=hpack.Encoder().encode(
314+
[
315+
(b":status", b"200"),
316+
(b"content-type", b"plain/text"),
317+
]
318+
),
319+
flags=["END_HEADERS"],
320+
).serialize(),
321+
hyperframe.frame.DataFrame(
322+
stream_id=1, data=b"Hello, world!", flags=["END_STREAM"]
323+
).serialize(),
324+
]
325+
)
326+
with HTTP2Connection(origin=origin, stream=stream) as conn:
327+
with conn.stream("GET", "https://example.com/") as response:
328+
response.read()
329+
assert conn._h2_state.remote_settings.max_concurrent_streams == 1000
330+
assert conn._max_streams == min(
331+
conn._h2_state.remote_settings.max_concurrent_streams,
332+
conn._h2_state.local_settings.max_concurrent_streams,
333+
)

0 commit comments

Comments
 (0)