mirror of
https://github.com/BerriAI/litellm.git
synced 2026-09-10 22:41:41 +00:00
Merge branch 'litellm_internal_staging' into litellm_/release-version-bump-787548
This commit is contained in:
commit
c417e1084d
3 changed files with 35 additions and 10 deletions
|
|
@ -6,7 +6,7 @@ import time
|
|||
from collections.abc import Generator
|
||||
from dataclasses import dataclass
|
||||
from pathlib import Path
|
||||
from typing import Optional
|
||||
from typing import Final, Optional
|
||||
|
||||
import pytest
|
||||
|
||||
|
|
@ -122,10 +122,18 @@ class FakePrismaCli:
|
|||
return [json.loads(line) for line in self.calls_file.read_text().splitlines()]
|
||||
|
||||
def grandchild_is_gone(self, within_seconds: float) -> bool:
|
||||
deadline = time.monotonic() + within_seconds
|
||||
pid: Final = int(self.grandchild_pidfile.read_text())
|
||||
deadline: Final = time.monotonic() + within_seconds
|
||||
while time.monotonic() < deadline:
|
||||
if os.name != "nt":
|
||||
try:
|
||||
reaped_pid, _ = os.waitpid(pid, os.WNOHANG)
|
||||
if reaped_pid == pid:
|
||||
return True
|
||||
except ChildProcessError:
|
||||
pass
|
||||
try:
|
||||
os.kill(int(self.grandchild_pidfile.read_text()), 0)
|
||||
os.kill(pid, 0)
|
||||
except ProcessLookupError:
|
||||
return True
|
||||
time.sleep(0.05)
|
||||
|
|
@ -154,3 +162,4 @@ def fake_prisma_cli(tmp_path: Path, monkeypatch: pytest.MonkeyPatch) -> Generato
|
|||
os.kill(int(cli.grandchild_pidfile.read_text()), signal.SIGKILL)
|
||||
except ProcessLookupError:
|
||||
pass
|
||||
assert cli.grandchild_is_gone(within_seconds=5)
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ import signal
|
|||
import subprocess
|
||||
import sys
|
||||
import time
|
||||
from typing import Final
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import pytest
|
||||
|
|
@ -15,7 +16,6 @@ from litellm.proxy.db.query_engine_reaper import (
|
|||
_try_reap,
|
||||
list_orphaned_engine_pids,
|
||||
reap_orphaned_engines,
|
||||
set_child_subreaper,
|
||||
start_query_engine_reaper,
|
||||
terminate_and_reap,
|
||||
terminate_and_reap_all,
|
||||
|
|
@ -79,11 +79,19 @@ class TestListOrphanedEnginePids:
|
|||
|
||||
class TestSetChildSubreaper:
|
||||
def test_matches_platform_capability(self):
|
||||
result = set_child_subreaper()
|
||||
if sys.platform.startswith("linux"):
|
||||
assert result is True
|
||||
else:
|
||||
assert result is False
|
||||
result: Final = subprocess.run(
|
||||
[
|
||||
sys.executable,
|
||||
"-c",
|
||||
"import sys; "
|
||||
"from litellm.proxy.db.query_engine_reaper import set_child_subreaper; "
|
||||
"assert set_child_subreaper() is sys.platform.startswith('linux')",
|
||||
],
|
||||
capture_output=True,
|
||||
text=True,
|
||||
timeout=30,
|
||||
)
|
||||
assert result.returncode == 0, result.stderr
|
||||
|
||||
|
||||
@pytest.mark.skipif(sys.platform == "win32", reason="POSIX signals and waitpid")
|
||||
|
|
|
|||
|
|
@ -1525,7 +1525,12 @@ class TestProxyInitializationHelpers:
|
|||
def capture_run(self):
|
||||
captured["options"] = dict(self.options)
|
||||
|
||||
with patch("gunicorn.app.base.BaseApplication.run", capture_run):
|
||||
with (
|
||||
patch("gunicorn.app.base.BaseApplication.run", capture_run),
|
||||
patch( # test-quality-ok: option tests must not start a thread or change the pytest worker's child ownership
|
||||
"litellm.proxy.proxy_cli.start_query_engine_reaper"
|
||||
),
|
||||
):
|
||||
ProxyInitializationHelpers._run_gunicorn_server(
|
||||
host="127.0.0.1",
|
||||
port=4010,
|
||||
|
|
@ -1553,6 +1558,9 @@ class TestProxyInitializationHelpers:
|
|||
with (
|
||||
patch("gunicorn.app.base.BaseApplication.run", capture_run),
|
||||
patch("builtins.print") as mock_print,
|
||||
patch( # test-quality-ok: option tests must not start a thread or change the pytest worker's child ownership
|
||||
"litellm.proxy.proxy_cli.start_query_engine_reaper"
|
||||
),
|
||||
):
|
||||
ProxyInitializationHelpers._run_gunicorn_server(
|
||||
host="127.0.0.1",
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue