-
-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Run one test using Hypercorn #3190
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
Conversation
522d8f7
to
eda6b12
Compare
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): |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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
.
dummyserver/testcase.py
Outdated
@@ -292,6 +294,26 @@ class IPv6HTTPDummyProxyTestCase(HTTPDummyProxyTestCase): | |||
proxy_host_alt = "127.0.0.1" | |||
|
|||
|
|||
class HypercornDummyServerTestCase: | |||
host: str = "localhost" | |||
port: str = "8080" |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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__) |
There was a problem hiding this comment.
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.
There was a problem hiding this 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!
dummyserver/testcase.py
Outdated
@@ -292,6 +294,26 @@ class IPv6HTTPDummyProxyTestCase(HTTPDummyProxyTestCase): | |||
proxy_host_alt = "127.0.0.1" | |||
|
|||
|
|||
class HypercornDummyServerTestCase: | |||
host: str = "localhost" | |||
port: str = "8080" |
There was a problem hiding this comment.
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 |
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks Quentin!
Closes #3038