Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow testing HTTP/1.1 and HTTP/2 in the same test #3310

Merged
merged 4 commits into from
Jan 24, 2024

Conversation

pquentin
Copy link
Member

@pquentin pquentin commented Jan 24, 2024

Closes #3194

We're using a parametrized fixture that when used, will run a given test twice, with HTTP/1.1 and HTTP/2. When used with HTTP/2, it injects HTTP/2 support (which currently forces the usage of HTTP/2). The value of the fixture is "h11" or "h2", which helps to check the header return by Hypercorn.

Things I can do differently:

  • instead of h11 and h2, I could use the ALPN names http/1.1 and h2, or the full names, HTTP/1.1 and HTTP/2. Or even a more named tuple containing all the previous values.
  • instead of using a parametrized fixture, I could use an explicit pytest.mark.parametrize as done by Hip. It's much more explicit (case in point, I had no idea that loopback_host was a parametrized fixture) but also a lot of work - AnyIO needs a lot of pytest code to make that work transparently.
  • instead of http_version, I could use a different name to clarify that this tests HTTP/1.1 and HTTP/2.2, but http_version is natural to use inside tests.

This pull request was sponsored by Elastic, my employer.

@pquentin pquentin added the Skip Changelog Pull requests that don't require a changelog entry label Jan 24, 2024
illia-v
illia-v previously approved these changes Jan 24, 2024
Copy link
Member

@illia-v illia-v left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The changes look great!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we rename this file to test_hypercorn_server.py now since the test uses both HTTP/1.1 and HTTP/2?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or maybe it's OK to drop that file altogether now?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point, I'm fine with dropping it since other tests start using HTTP/2

@pquentin pquentin merged commit 71e7c35 into urllib3:main Jan 24, 2024
33 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Skip Changelog Pull requests that don't require a changelog entry
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Create a mechanism to test different HTTP protocols (HTTP/1.1 and HTTP/2) with the same test case
2 participants