Skip to content

Conversation

pquentin
Copy link
Member

@pquentin pquentin commented Nov 15, 2023

Closes #3038

@pquentin pquentin added the Skip Changelog Pull requests that don't require a changelog entry label Nov 15, 2023
from urllib3 import HTTPHeaderDict, HTTPResponse, request
from urllib3.connectionpool import port_by_scheme
from urllib3.exceptions import MaxRetryError, URLSchemeUnknown
from urllib3.poolmanager import PoolManager
from urllib3.util.retry import Retry


class TestHypercornPoolManager(HypercornDummyServerTestCase):
Copy link
Member Author

Choose a reason for hiding this comment

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

The idea is to make TestPoolManager a subclass of HypercornDummyServerTestCase, but starting with a separate class was easier as my focus for this pull request was to make HypercornDummyServerTestCase work.

Copy link
Member

Choose a reason for hiding this comment

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

++ I'm happy with this for the first case!


@classmethod
def setup_class(cls) -> None:
with contextlib.ExitStack() as stack:
Copy link
Member Author

Choose a reason for hiding this comment

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

It would have been easy to use a pytest fixture with the run_hypercorn_in_thread context manager, but I wanted to mirror the existing TestCase convention which makes it very easy to attach class variables like base_url.

@@ -292,6 +294,26 @@ class IPv6HTTPDummyProxyTestCase(HTTPDummyProxyTestCase):
proxy_host_alt = "127.0.0.1"


class HypercornDummyServerTestCase:
host: str = "localhost"
port: str = "8080"
Copy link
Member Author

Choose a reason for hiding this comment

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

With Tornado, we use the port 0 (None in Python), but that does not seem to be possible with Hypercorn.

Copy link
Member

Choose a reason for hiding this comment

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

That's a shame, can we open an issue on Hypercorn for this feature and link back to this?

Copy link

Choose a reason for hiding this comment

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

It should be, pgjones/hypercorn#19

Copy link
Member Author

@pquentin pquentin Nov 15, 2023

Choose a reason for hiding this comment

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

Oh, right, thanks for the tip! I've addressed in 931c749 by sneakily abusing task_status.started to overwrite config.bind.

@@ -362,3 +363,11 @@ def redirect_after(self, request: httputil.HTTPServerRequest) -> Response:

def shutdown(self, request: httputil.HTTPServerRequest) -> typing.NoReturn:
sys.exit()


hypercorn_app = QuartTrio(__name__)
Copy link
Member Author

Choose a reason for hiding this comment

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

I think this should be in its own file.

Copy link
Member

@sethmlarson sethmlarson left a comment

Choose a reason for hiding this comment

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

This is awesome, I don't have any blocking comments only some suggestions. Thanks so much @pquentin!

@@ -292,6 +294,26 @@ class IPv6HTTPDummyProxyTestCase(HTTPDummyProxyTestCase):
proxy_host_alt = "127.0.0.1"


class HypercornDummyServerTestCase:
host: str = "localhost"
port: str = "8080"
Copy link
Member

Choose a reason for hiding this comment

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

That's a shame, can we open an issue on Hypercorn for this feature and link back to this?

@@ -10,7 +10,8 @@
def tests_impl(
session: nox.Session,
extras: str = "socks,brotli,zstd",
byte_string_comparisons: bool = True,
# hypercorn dependency h2 compares bytes and strings
Copy link
Member

Choose a reason for hiding this comment

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

Can we create an issue on h2 for this? Would be good to keep this one enabled.

Copy link
Member Author

Choose a reason for hiding this comment

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

Thanks, I added a link to python-hyper/h2#1236 in be8f4e7. Seems difficult to fix at first glance.

from urllib3 import HTTPHeaderDict, HTTPResponse, request
from urllib3.connectionpool import port_by_scheme
from urllib3.exceptions import MaxRetryError, URLSchemeUnknown
from urllib3.poolmanager import PoolManager
from urllib3.util.retry import Retry


class TestHypercornPoolManager(HypercornDummyServerTestCase):
Copy link
Member

Choose a reason for hiding this comment

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

++ I'm happy with this for the first case!

Copy link
Member

@sethmlarson sethmlarson left a comment

Choose a reason for hiding this comment

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

LGTM, thanks Quentin!

@sethmlarson sethmlarson merged commit 402cba1 into urllib3:main Nov 16, 2023
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.

Add an HTTP/2-capable handler to the test suite
3 participants