Handle missing Java service executable

This commit is contained in:
王鹏
2026-10-10 16:35:29 +08:00
parent dd4763a4a7
commit e1c58d8117
4 changed files with 63 additions and 0 deletions

View File

@@ -67,6 +67,30 @@ class ServiceConsoleTests(unittest.TestCase):
self.assertIn("java-service-ready", log_path.read_text(encoding="utf-8"))
self.assertFalse(pid_path.exists())
def test_missing_service_executable_is_logged_without_unhandled_exception(self):
with tempfile.TemporaryDirectory() as temp:
root = Path(temp)
log_path = root / "service.log"
pid_path = root / "service.pid"
missing_executable = root / "missing-java.exe"
argv = [
"service_console.py",
"--log",
str(log_path),
"--pid-file",
str(pid_path),
"--",
str(missing_executable),
"-version",
]
with patch.object(sys, "argv", argv):
exit_code = main()
self.assertEqual(exit_code, 1)
self.assertIn("无法启动服务命令", log_path.read_text(encoding="utf-8"))
self.assertFalse(pid_path.exists())
if __name__ == "__main__":
unittest.main()