diff options
| author | historia <historiavg@proton.me> | 2026-08-26 00:21:28 -0400 |
|---|---|---|
| committer | historia <historiavg@proton.me> | 2026-08-26 00:21:28 -0400 |
| commit | 7cf7d2f7849936e3c84ee431433c2e8bcb6706ac (patch) | |
| tree | 80d753cbd35929187ffc717a45f7bc3e9cbdbb1e /app/tests/test_backends_servers.py | |
| parent | 4c3e78c39c81d2997e88b84e1b5a25b244e870e4 (diff) | |
| download | tts-audiobook-generator-7cf7d2f7849936e3c84ee431433c2e8bcb6706ac.tar.gz | |
fix: harden server start/stop guards
Diffstat (limited to 'app/tests/test_backends_servers.py')
| -rw-r--r-- | app/tests/test_backends_servers.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/app/tests/test_backends_servers.py b/app/tests/test_backends_servers.py index 8eaf53f..ab05eed 100644 --- a/app/tests/test_backends_servers.py +++ b/app/tests/test_backends_servers.py @@ -35,6 +35,23 @@ class StartTests(unittest.TestCase): self.assertTrue(servers.start(self.spec)) mk.assert_not_called() + def test_refuses_to_double_start_while_previous_boot_is_alive(self): + """A live pid file blocks a second spawn of the same server. + + A previous ``start`` whose server is still booting must not be + orphaned by a duplicate process on the same port. + """ + pid_file = self.dir / "test-server.pid" + pid_file.write_text("4242", encoding="utf-8") + with patch.object(servers, "LOG_DIR", self.dir), \ + patch.object(servers, "_pid_alive", return_value=True), \ + patch("subprocess.Popen") as mk, \ + patch("backends.common.server_running", return_value=False): + ok = servers.start(self.spec) + self.assertFalse(ok) + mk.assert_not_called() + self.assertTrue(pid_file.exists()) + def test_happy_path_spawns_and_polls_until_ready(self): proc = MagicMock() proc.pid = 4242 |
