Skip to content

Commit

Permalink
Merge branch 'master' of github.com:encode/uvicorn into drop-pytest-a…
Browse files Browse the repository at this point in the history
…syncio
  • Loading branch information
graingert committed Jun 14, 2022
2 parents 873217d + f4bb5ea commit 4be1085
Show file tree
Hide file tree
Showing 16 changed files with 436 additions and 205 deletions.
4 changes: 2 additions & 2 deletions CHANGELOG.md
Expand Up @@ -83,7 +83,7 @@
- Allow WebSocket close event to receive reason being None from ASGI app. (#1259) 23/11/21
- Fix a bug in `WebSocketProtocol.asgi_receive` on which we returned a close frame even if there were data messages before that frame in the read queue. (#1252) 25/11/21
- The option `--reload-dirs` was splitting a string into single character directories. (#1267) 25/11/21
- Only second SIGINT is able to forcelly shutdown the server (#1269) 28/11/21
- Only second SIGINT is able to forcefully shutdown the server (#1269) 28/11/21
- Allow app-dir parameter on the run() function (#1271) 06/12/21


Expand Down Expand Up @@ -197,7 +197,7 @@
### Fixed
- Fixes watchgod with common prefixes (#817) 10/14/20 1b32f997
- Fix reload with ipv6 host (#803) 10/14/20 5acaee5b
- Added cli suport for headers containing colon (#813) 10/12/20 68732899
- Added cli support for headers containing colon (#813) 10/12/20 68732899
- Sharing socket across workers on windows (#802) 10/12/20 103167a0
- Note the need to configure trusted "ips" when using unix sockets (#796) 10/4/20 a504c569

Expand Down
2 changes: 1 addition & 1 deletion docs/deployment.md
Expand Up @@ -88,7 +88,7 @@ Options:
Enable/Disable default Server header.
--date-header / --no-date-header
Enable/Disable default Date header.
--forwarded-allow-ips TEXT Comma seperated list of IPs to trust with
--forwarded-allow-ips TEXT Comma separated list of IPs to trust with
proxy headers. Defaults to the
$FORWARDED_ALLOW_IPS environment variable if
available, or '127.0.0.1'.
Expand Down
2 changes: 1 addition & 1 deletion docs/index.md
Expand Up @@ -155,7 +155,7 @@ Options:
Enable/Disable default Server header.
--date-header / --no-date-header
Enable/Disable default Date header.
--forwarded-allow-ips TEXT Comma seperated list of IPs to trust with
--forwarded-allow-ips TEXT Comma separated list of IPs to trust with
proxy headers. Defaults to the
$FORWARDED_ALLOW_IPS environment variable if
available, or '127.0.0.1'.
Expand Down
10 changes: 5 additions & 5 deletions requirements.txt
Expand Up @@ -12,17 +12,17 @@ autoflake==1.4
black==22.3.0
flake8==3.9.2
isort==5.10.1
pytest==6.2.5
pytest-mock==3.6.1
mypy==0.950
pytest==7.1.2
pytest-mock==3.7.0
mypy==0.960
types-click==7.1.8
types-pyyaml==6.0.7
trustme==0.9.0
cryptography==3.4.8
coverage==6.3.2
coverage==6.4
coverage-conditional-plugin==0.5.0
httpx==1.0.0b0

# Documentation
mkdocs==1.3.0
mkdocs-material==8.2.12
mkdocs-material==8.2.16
4 changes: 4 additions & 0 deletions setup.cfg
Expand Up @@ -36,6 +36,8 @@ files =
uvicorn/protocols/__init__.py,
uvicorn/protocols/http/__init__.py,
uvicorn/protocols/websockets/__init__.py,
uvicorn/protocols/http/h11_impl.py,
uvicorn/protocols/http/httptools_impl.py,
tests/middleware/test_wsgi.py,
tests/middleware/test_proxy_headers.py,
tests/test_config.py,
Expand All @@ -47,6 +49,8 @@ files =
tests/importer,
tests/response.py,
tests/__init__.py,
tests/supervisors/test_multiprocess.py,
tests/test_ssl.py,
tests/utils.py


Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Expand Up @@ -177,7 +177,7 @@ def make_tmp_dir(base_dir):
sock_path = str(tmpd / socket_filename)
sock_path_len = len(sock_path.encode())
if sock_path_len <= max_sock_len:
if max_sock_len - sock_path_len >= identifier_len:
if max_sock_len - sock_path_len >= identifier_len: # pragma: no cover
sock_path = str(tmpd / "".join((identifier, socket_filename)))
yield sock_path
return
2 changes: 1 addition & 1 deletion tests/protocols/test_http.py
Expand Up @@ -784,7 +784,7 @@ def send_fragmented_req(path):
# we skip the error on bsd systems if python is too slow
try:
sock.shutdown(socket.SHUT_RDWR)
except Exception: # pragma: py-linux
except Exception: # pragma: no cover
pass
sock.close()
return resp
Expand Down
2 changes: 1 addition & 1 deletion tests/protocols/test_websocket.py
Expand Up @@ -220,7 +220,7 @@ async def websocket_connect(self, message):
path = self.scope.get("path")
raw_path = self.scope.get("raw_path")
assert path == "/one/two"
assert raw_path == "/one%2Ftwo"
assert raw_path == b"/one%2Ftwo"
await self.send({"type": "websocket.accept"})

async def open_connection(url):
Expand Down
14 changes: 11 additions & 3 deletions tests/supervisors/test_multiprocess.py
@@ -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()
49 changes: 49 additions & 0 deletions tests/test_subprocess.py
@@ -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()

0 comments on commit 4be1085

Please sign in to comment.