This commit is contained in:
cotran 2024-10-24 15:29:22 -07:00
parent 2a4b5ec9fb
commit 4b012ffd8c
2 changed files with 10 additions and 6 deletions

View file

@ -2,7 +2,7 @@ import unittest
from unittest.mock import patch, MagicMock
import subprocess
import time
from app.cli import stop_server
from app.cli import kill_process
class TestStopServer(unittest.TestCase):
@ -11,7 +11,7 @@ class TestStopServer(unittest.TestCase):
# Mock subprocess.run to simulate no process listening on the port
mock_run.return_value.returncode = 1
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.")
@patch("subprocess.run")
@ -23,7 +23,7 @@ class TestStopServer(unittest.TestCase):
MagicMock(returncode=1), # for checking the process after it is killed
]
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("Process 1234 has been killed.")
@ -42,7 +42,7 @@ class TestStopServer(unittest.TestCase):
]
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
mock_print.assert_any_call("Killing model server process with PID 1234")