Clean marked trial engine processes

This commit is contained in:
2026-05-16 15:51:04 +08:00
parent cf9b8b3f68
commit d0c89dac48
2 changed files with 76 additions and 7 deletions

View File

@@ -2,6 +2,7 @@ from __future__ import annotations
import json
import os
import signal
import subprocess
import tempfile
import unittest
@@ -4573,6 +4574,26 @@ class CoreFlowTests(unittest.TestCase):
self.assertEqual(mock_killpg.call_args_list[0].args[0], 1234)
process.wait.assert_not_called()
def test_terminate_process_tree_signals_marker_processes_when_group_missing(self) -> None:
process = mock.Mock()
process.pid = 1234
process.poll.return_value = 0
marker_env = {"AITUNER_TRIAL_ID": "trial-0001"}
with mock.patch("aituner.worker.os.getpgid", side_effect=ProcessLookupError):
with mock.patch("aituner.worker.os.killpg", side_effect=ProcessLookupError):
with mock.patch(
"aituner.worker._pids_matching_env",
side_effect=[[2222], []],
) as mock_pids:
with mock.patch("aituner.worker._signal_pids") as mock_signal:
_terminate_process_tree(
process,
timeout_s=1.0,
marker_env=marker_env,
)
self.assertEqual(mock_pids.call_args_list[0].args[0], marker_env)
self.assertEqual(mock_signal.call_args_list[0].args, ([2222], signal.SIGTERM))
def test_openai_url_avoids_double_v1(self) -> None:
self.assertEqual(
_openai_url("http://example.com", "/v1/chat/completions"),