Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'master' of github.com:encode/uvicorn into drop-pytest-a…
…syncio
- Loading branch information
Showing
16 changed files
with
436 additions
and
205 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,29 @@ | ||
import signal | ||
import socket | ||
from typing import List, Optional | ||
|
||
from asgiref.typing import ASGIReceiveCallable, ASGISendCallable, Scope | ||
|
||
from uvicorn import Config | ||
from uvicorn.supervisors import Multiprocess | ||
|
||
|
||
def run(sockets): | ||
def app(scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable) -> None: | ||
pass # pragma: no cover | ||
|
||
|
||
def run(sockets: Optional[List[socket.socket]]) -> None: | ||
pass # pragma: no cover | ||
|
||
|
||
def test_multiprocess_run(): | ||
def test_multiprocess_run() -> None: | ||
""" | ||
A basic sanity check. | ||
Simply run the supervisor against a no-op server, and signal for it to | ||
quit immediately. | ||
""" | ||
config = Config(app=None, workers=2) | ||
config = Config(app=app, workers=2) | ||
supervisor = Multiprocess(config, target=run, sockets=[]) | ||
supervisor.signal_handler(sig=signal.SIGINT, frame=None) | ||
supervisor.run() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import socket | ||
import sys | ||
from typing import List | ||
from unittest.mock import patch | ||
|
||
import pytest | ||
from asgiref.typing import ASGIReceiveCallable, ASGISendCallable, Scope | ||
|
||
from uvicorn._subprocess import SpawnProcess, get_subprocess, subprocess_started | ||
from uvicorn.config import Config | ||
|
||
|
||
def server_run(sockets: List[socket.socket]): # pragma: no cover | ||
... | ||
|
||
|
||
async def app( | ||
scope: Scope, receive: ASGIReceiveCallable, send: ASGISendCallable | ||
) -> None: # pragma: no cover | ||
... | ||
|
||
|
||
@pytest.mark.skipif(sys.platform == "win32", reason="require unix-like system") | ||
def test_get_subprocess() -> None: # pragma: py-win32 | ||
fdsock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
fd = fdsock.fileno() | ||
config = Config(app=app, fd=fd) | ||
config.load() | ||
|
||
process = get_subprocess(config, server_run, [fdsock]) | ||
assert isinstance(process, SpawnProcess) | ||
|
||
fdsock.close() | ||
|
||
|
||
@pytest.mark.skipif(sys.platform == "win32", reason="require unix-like system") | ||
def test_subprocess_started() -> None: # pragma: py-win32 | ||
fdsock = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) | ||
fd = fdsock.fileno() | ||
config = Config(app=app, fd=fd) | ||
config.load() | ||
|
||
with patch("tests.test_subprocess.server_run") as mock_run: | ||
with patch.object(config, "configure_logging") as mock_config_logging: | ||
subprocess_started(config, server_run, [fdsock], None) | ||
mock_run.assert_called_once() | ||
mock_config_logging.assert_called_once() | ||
|
||
fdsock.close() |
Oops, something went wrong.