Skip to content

Commit

Permalink
Add test for remote max streams update
Browse files Browse the repository at this point in the history
  • Loading branch information
dunkmann00 committed Feb 28, 2023
1 parent ea68566 commit f7aefc6
Showing 1 changed file with 37 additions and 0 deletions.
37 changes: 37 additions & 0 deletions tests/_async/test_http2.py
Original file line number Diff line number Diff line change
Expand Up @@ -294,3 +294,40 @@ async def test_http2_request_to_incorrect_origin():
async with AsyncHTTP2Connection(origin=origin, stream=stream) as conn:
with pytest.raises(RuntimeError):
await conn.request("GET", "https://other.com/")


@pytest.mark.anyio
async def test_http2_remote_max_streams_update():
"""
If the remote server updates the maximum concurrent streams value, we should
be adjusting how many streams we will allow.
"""
origin = Origin(b"https", b"example.com", 443)
stream = AsyncMockStream(
[
hyperframe.frame.SettingsFrame(
settings={hyperframe.frame.SettingsFrame.MAX_CONCURRENT_STREAMS: 1000}
).serialize(),
hyperframe.frame.HeadersFrame(
stream_id=1,
data=hpack.Encoder().encode(
[
(b":status", b"200"),
(b"content-type", b"plain/text"),
]
),
flags=["END_HEADERS"],
).serialize(),
hyperframe.frame.DataFrame(
stream_id=1, data=b"Hello, world!", flags=["END_STREAM"]
).serialize(),
]
)
async with AsyncHTTP2Connection(origin=origin, stream=stream) as conn:
async with conn.stream("GET", "https://example.com/") as response:
await response.aread()
assert conn._h2_state.remote_settings.max_concurrent_streams == 1000
assert conn._max_streams == min(
conn._h2_state.remote_settings.max_concurrent_streams,
conn._h2_state.local_settings.max_concurrent_streams,
)

0 comments on commit f7aefc6

Please sign in to comment.