-
-
Notifications
You must be signed in to change notification settings - Fork 11.7k
Add granian as a ASGI compliant web server. Provider better throughput stability, #26027
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
Changes from all commits
ac77396
8bd0008
3064335
fdc9c05
7322b33
8ca6142
290b9e5
1c2869d
ce151f5
70e7013
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Large diffs are not rendered by default.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,11 @@ | ||
| import os | ||
| import sys | ||
| from pathlib import Path | ||
| from types import SimpleNamespace | ||
| from unittest.mock import AsyncMock, MagicMock, patch | ||
|
|
||
| import click | ||
| import fastapi | ||
| import pytest | ||
|
|
||
| sys.path.insert( | ||
|
|
@@ -231,6 +235,96 @@ def test_init_hypercorn_server(self, mock_print, mock_asyncio_run): | |
| mock_app, "localhost", 8000, "cert.pem", "key.pem", "ECDHE" | ||
| ) | ||
|
|
||
| @patch("granian.Granian") | ||
| @patch("builtins.print") | ||
| def test_init_granian_server(self, mock_print, mock_granian_cls): | ||
| pytest.importorskip("granian") | ||
|
harish-berri marked this conversation as resolved.
|
||
| mock_server = MagicMock() | ||
| mock_granian_cls.return_value = mock_server | ||
| fake_interfaces = SimpleNamespace(ASGI="asgi") | ||
| with patch("granian.constants.Interfaces", fake_interfaces): | ||
| ProxyInitializationHelpers._init_granian_server( | ||
| host="0.0.0.0", | ||
| port=4000, | ||
| num_workers=2, | ||
| ssl_certfile_path=None, | ||
| ssl_keyfile_path=None, | ||
| max_requests_before_restart=None, | ||
| ciphers=None, | ||
| granian_runtime_threads=None, | ||
| ) | ||
| mock_granian_cls.assert_called_once() | ||
| call_kwargs = mock_granian_cls.call_args.kwargs | ||
| assert call_kwargs["target"] == "litellm.proxy.proxy_server:app" | ||
| assert call_kwargs["address"] == "0.0.0.0" | ||
| assert call_kwargs["port"] == 4000 | ||
| assert call_kwargs["workers"] == 2 | ||
| assert call_kwargs["interface"] == "asgi" | ||
| assert call_kwargs["websockets"] is True | ||
| assert "runtime_threads" not in call_kwargs | ||
| mock_server.serve.assert_called_once() | ||
|
|
||
| @patch("granian.Granian") | ||
| @patch("builtins.print") | ||
| def test_init_granian_server_runtime_threads(self, mock_print, mock_granian_cls): | ||
| pytest.importorskip("granian") | ||
| mock_server = MagicMock() | ||
| mock_granian_cls.return_value = mock_server | ||
| fake_interfaces = SimpleNamespace(ASGI="asgi") | ||
| with patch("granian.constants.Interfaces", fake_interfaces): | ||
| ProxyInitializationHelpers._init_granian_server( | ||
| host="0.0.0.0", | ||
| port=4000, | ||
| num_workers=1, | ||
| ssl_certfile_path=None, | ||
| ssl_keyfile_path=None, | ||
| max_requests_before_restart=None, | ||
| ciphers=None, | ||
| granian_runtime_threads=4, | ||
| ) | ||
| assert mock_granian_cls.call_args.kwargs["runtime_threads"] == 4 | ||
|
|
||
| @patch("granian.Granian") | ||
| @patch("builtins.print") | ||
| def test_init_granian_server_ssl(self, mock_print, mock_granian_cls): | ||
| pytest.importorskip("granian") | ||
| mock_server = MagicMock() | ||
| mock_granian_cls.return_value = mock_server | ||
| fake_interfaces = SimpleNamespace(ASGI="asgi") | ||
| with patch("granian.constants.Interfaces", fake_interfaces): | ||
| ProxyInitializationHelpers._init_granian_server( | ||
| host="0.0.0.0", | ||
| port=4000, | ||
| num_workers=1, | ||
| ssl_certfile_path="/path/to/cert.pem", | ||
| ssl_keyfile_path="/path/to/key.pem", | ||
| max_requests_before_restart=None, | ||
| ciphers=None, | ||
| granian_runtime_threads=None, | ||
| ) | ||
| call_kwargs = mock_granian_cls.call_args.kwargs | ||
| assert call_kwargs["ssl_cert"] == Path("/path/to/cert.pem") | ||
| assert call_kwargs["ssl_key"] == Path("/path/to/key.pem") | ||
| mock_server.serve.assert_called_once() | ||
|
|
||
| @patch("granian.Granian") | ||
| def test_init_granian_server_ssl_requires_cert_and_key(self, mock_granian_cls): | ||
| pytest.importorskip("granian") | ||
| fake_interfaces = SimpleNamespace(ASGI="asgi") | ||
| with patch("granian.constants.Interfaces", fake_interfaces): | ||
| with pytest.raises(click.ClickException, match="Both --ssl_certfile_path"): | ||
| ProxyInitializationHelpers._init_granian_server( | ||
| host="0.0.0.0", | ||
| port=4000, | ||
| num_workers=1, | ||
| ssl_certfile_path="/path/to/cert.pem", | ||
| ssl_keyfile_path=None, | ||
| max_requests_before_restart=None, | ||
| ciphers=None, | ||
| granian_runtime_threads=None, | ||
| ) | ||
| mock_granian_cls.assert_not_called() | ||
|
Comment on lines
+287
to
+326
Contributor
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.
The three newly added SSL tests ( |
||
|
|
||
| @patch("subprocess.Popen") | ||
| def test_run_ollama_serve(self, mock_popen): | ||
| # Execute | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.