-
-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
Fix Ctrl+C and tests on Windows. #1808
Changes from all commits
33388e6
6ea8183
68fb963
da26adf
1580ca6
2356165
6f536a1
77a0e04
ae03fce
fda9556
1418003
5f8fc0c
036c1d7
dc5d682
46484eb
6f55780
73a2416
66ff770
ed17a3c
41dff40
f58319f
fd2ba55
d3c8dd4
8514d1f
2b8a8dc
1257bd3
1c40860
b4f47e2
b3a38b7
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -12,7 +12,7 @@ | |
|
||
ASGI_HOST = "mockserver" | ||
HOST = "127.0.0.1" | ||
PORT = 42101 | ||
PORT = None | ||
|
||
|
||
class SanicTestClient: | ||
|
@@ -95,14 +95,15 @@ async def error_handler(request, exception): | |
|
||
if self.port: | ||
server_kwargs = dict( | ||
host=host or self.host, port=self.port, **server_kwargs | ||
host=host or self.host, port=self.port, **server_kwargs, | ||
) | ||
host, port = host or self.host, self.port | ||
else: | ||
sock = socket() | ||
sock.bind((host or self.host, 0)) | ||
server_kwargs = dict(sock=sock, **server_kwargs) | ||
host, port = sock.getsockname() | ||
self.port = port | ||
|
||
if uri.startswith( | ||
("http:", "https:", "ftp:", "ftps://", "//", "ws:", "wss:") | ||
|
@@ -114,6 +115,9 @@ async def error_handler(request, exception): | |
url = "{scheme}://{host}:{port}{uri}".format( | ||
scheme=scheme, host=host, port=port, uri=uri | ||
) | ||
# Tests construct URLs using PORT = None, which means random port not | ||
# known until this function is called, so fix that here | ||
url = url.replace(":None/", f":{port}/") | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. a little bit concern on this, probably should avoid this kinda of hacky pattern. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoiding this would require major restructuring of |
||
|
||
@self.app.listener("after_server_start") | ||
async def _collect_response(sanic, loop): | ||
|
@@ -203,7 +207,7 @@ def __init__( | |
|
||
self.app = app | ||
|
||
dispatch = SanicASGIDispatch(app=app, client=(ASGI_HOST, PORT)) | ||
dispatch = SanicASGIDispatch(app=app, client=(ASGI_HOST, PORT or 0)) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why 0 ? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Typing says it needs to be int, so There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Actually all of Sanic should probably be changed to accept 0 port. Currently entering zero gives port 8000. But that is a potentially breaking change, and for another PR even if implemented. |
||
super().__init__(dispatch=dispatch, base_url=base_url) | ||
|
||
self.last_request = None | ||
|
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.
What's the diff between
is_running
andis_stopping
?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.
When the app has not yet started, both are False. After calling
app.stop
the app may keep running for a while, so in that period both are True. Asyncio implementation usesloop._stopping
in a similar fashion but uvloop doesn't have that and depending on private parts of the implementation is ugly in any case.