fix: keep agent alive across worker crashes
This commit is contained in:
@@ -46,6 +46,31 @@ class HostedAgentEntrypointTests(unittest.TestCase):
|
||||
self.assertNotIn("apt-get", dockerfile)
|
||||
self.assertIn("dulwich", requirements.casefold())
|
||||
|
||||
def test_exited_worker_is_backed_off_without_exiting_supervisor(self) -> None:
|
||||
class ExitedWorker:
|
||||
def poll(self) -> int:
|
||||
return 137
|
||||
|
||||
with tempfile.TemporaryDirectory() as temporary_dir:
|
||||
root = Path(temporary_dir)
|
||||
with (
|
||||
patch.object(ENTRYPOINT, "worker", ExitedWorker()),
|
||||
patch.object(ENTRYPOINT, "worker_start_enabled", True),
|
||||
patch.object(ENTRYPOINT, "shutdown_requested", False),
|
||||
patch.object(ENTRYPOINT, "config_error", None),
|
||||
patch.object(ENTRYPOINT, "worker_started_at", 90.0),
|
||||
patch.object(ENTRYPOINT, "worker_restart_count", 0),
|
||||
patch.object(ENTRYPOINT, "worker_next_restart_at", 0.0),
|
||||
patch.object(ENTRYPOINT, "WORKER_CRASH_PATH", root / "worker_crashes.jsonl"),
|
||||
patch.object(ENTRYPOINT, "READINESS_PATH", root / "readiness.json"),
|
||||
):
|
||||
ENTRYPOINT._supervise_worker(now=100.0)
|
||||
self.assertIsNone(ENTRYPOINT.worker)
|
||||
self.assertEqual(1, ENTRYPOINT.worker_restart_count)
|
||||
self.assertEqual(105.0, ENTRYPOINT.worker_next_restart_at)
|
||||
self.assertEqual("worker_restarting", ENTRYPOINT._readiness()["reason"])
|
||||
self.assertIn('"exitCode":137', (root / "worker_crashes.jsonl").read_text(encoding="utf-8"))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
Reference in New Issue
Block a user