mirror of
https://github.com/katanemo/plano.git
synced 2026-07-02 15:51:02 +02:00
reformat
This commit is contained in:
parent
2a4b5ec9fb
commit
4b012ffd8c
2 changed files with 10 additions and 6 deletions
|
|
@ -98,12 +98,11 @@ def check_and_install_lsof():
|
||||||
print(f"Failed to install lsof: {install_error}")
|
print(f"Failed to install lsof: {install_error}")
|
||||||
|
|
||||||
|
|
||||||
def stop_server(port=51000, wait=True, timeout=10):
|
def kill_process(port=51000, wait=True, timeout=10):
|
||||||
"""Stop the running Uvicorn server."""
|
"""Stop the running Uvicorn server."""
|
||||||
log.info("Stopping model server")
|
log.info("Stopping model server")
|
||||||
try:
|
try:
|
||||||
# Run the function to check and install lsof if necessary
|
# Run the function to check and install lsof if necessary
|
||||||
check_and_install_lsof()
|
|
||||||
# Step 1: Run lsof command to get the process using the port
|
# Step 1: Run lsof command to get the process using the port
|
||||||
lsof_command = f"lsof -n | grep {port} | grep -i LISTEN"
|
lsof_command = f"lsof -n | grep {port} | grep -i LISTEN"
|
||||||
result = subprocess.run(
|
result = subprocess.run(
|
||||||
|
|
@ -156,6 +155,11 @@ def stop_server(port=51000, wait=True, timeout=10):
|
||||||
print(f"Error occurred: {e}")
|
print(f"Error occurred: {e}")
|
||||||
|
|
||||||
|
|
||||||
|
def stop_server(port=51000, wait=True, timeout=10):
|
||||||
|
check_and_install_lsof()
|
||||||
|
kill_process(port, wait, timeout)
|
||||||
|
|
||||||
|
|
||||||
def restart_server(port=51000):
|
def restart_server(port=51000):
|
||||||
"""Restart the Uvicorn server."""
|
"""Restart the Uvicorn server."""
|
||||||
stop_server(port)
|
stop_server(port)
|
||||||
|
|
|
||||||
|
|
@ -2,7 +2,7 @@ import unittest
|
||||||
from unittest.mock import patch, MagicMock
|
from unittest.mock import patch, MagicMock
|
||||||
import subprocess
|
import subprocess
|
||||||
import time
|
import time
|
||||||
from app.cli import stop_server
|
from app.cli import kill_process
|
||||||
|
|
||||||
|
|
||||||
class TestStopServer(unittest.TestCase):
|
class TestStopServer(unittest.TestCase):
|
||||||
|
|
@ -11,7 +11,7 @@ class TestStopServer(unittest.TestCase):
|
||||||
# Mock subprocess.run to simulate no process listening on the port
|
# Mock subprocess.run to simulate no process listening on the port
|
||||||
mock_run.return_value.returncode = 1
|
mock_run.return_value.returncode = 1
|
||||||
with patch("builtins.print") as mock_print:
|
with patch("builtins.print") as mock_print:
|
||||||
stop_server(port=51000)
|
kill_process(port=51000)
|
||||||
mock_print.assert_called_with("No process found listening on port 51000.")
|
mock_print.assert_called_with("No process found listening on port 51000.")
|
||||||
|
|
||||||
@patch("subprocess.run")
|
@patch("subprocess.run")
|
||||||
|
|
@ -23,7 +23,7 @@ class TestStopServer(unittest.TestCase):
|
||||||
MagicMock(returncode=1), # for checking the process after it is killed
|
MagicMock(returncode=1), # for checking the process after it is killed
|
||||||
]
|
]
|
||||||
with patch("builtins.print") as mock_print:
|
with patch("builtins.print") as mock_print:
|
||||||
stop_server(port=51000, wait=True, timeout=5)
|
kill_process(port=51000, wait=True, timeout=5)
|
||||||
mock_print.assert_any_call("Killing model server process with PID 1234")
|
mock_print.assert_any_call("Killing model server process with PID 1234")
|
||||||
mock_print.assert_any_call("Process 1234 has been killed.")
|
mock_print.assert_any_call("Process 1234 has been killed.")
|
||||||
|
|
||||||
|
|
@ -42,7 +42,7 @@ class TestStopServer(unittest.TestCase):
|
||||||
]
|
]
|
||||||
|
|
||||||
with patch("builtins.print") as mock_print:
|
with patch("builtins.print") as mock_print:
|
||||||
stop_server(port=51000, wait=True, timeout=5)
|
kill_process(port=51000, wait=True, timeout=5)
|
||||||
|
|
||||||
# Assert that the function tried to kill both PIDs
|
# Assert that the function tried to kill both PIDs
|
||||||
mock_print.assert_any_call("Killing model server process with PID 1234")
|
mock_print.assert_any_call("Killing model server process with PID 1234")
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue