Drive the retry line in the main test from zero failures
This commit is contained in:
@@ -277,14 +277,14 @@ else:
|
|||||||
|
|
||||||
class RunWorker(unittest.TestCase):
|
class RunWorker(unittest.TestCase):
|
||||||
def test_says_whether_a_non_zero_exit_or_a_missing_result_event_failed_it(self):
|
def test_says_whether_a_non_zero_exit_or_a_missing_result_event_failed_it(self):
|
||||||
with tempfile.TemporaryDirectory() as home:
|
with tempfile.TemporaryDirectory() as bin:
|
||||||
stub = os.path.join(home, "claude")
|
stub = os.path.join(bin, "claude")
|
||||||
scripts = {
|
scripts = {
|
||||||
"": 'print(json.dumps({"type": "result"}))',
|
"": 'print(json.dumps({"type": "result"}))',
|
||||||
"claude exited 0 without a result event": 'print(json.dumps({"type": "assistant", "message": {"content": [{"type": "text", "text": "worked"}]}}))',
|
"claude exited 0 without a result event": 'print(json.dumps({"type": "assistant", "message": {"content": [{"type": "text", "text": "worked"}]}}))',
|
||||||
"claude exited 3": "sys.exit(3)",
|
"claude exited 3": "sys.exit(3)",
|
||||||
}
|
}
|
||||||
with unittest.mock.patch.dict(os.environ, {"PATH": f"{home}:{os.environ['PATH']}"}), unittest.mock.patch.object(sys, "stdout", io.StringIO()):
|
with unittest.mock.patch.dict(os.environ, {"PATH": f"{bin}:{os.environ['PATH']}"}), unittest.mock.patch.object(sys, "stdout", io.StringIO()):
|
||||||
for failure, script in scripts.items():
|
for failure, script in scripts.items():
|
||||||
open(stub, "w").write(f"#!/usr/bin/env python3\nimport json\nimport sys\n{script}\n")
|
open(stub, "w").write(f"#!/usr/bin/env python3\nimport json\nimport sys\n{script}\n")
|
||||||
os.chmod(stub, 0o700)
|
os.chmod(stub, 0o700)
|
||||||
@@ -355,9 +355,13 @@ class Main(unittest.TestCase):
|
|||||||
mocks[2].assert_called_once_with("do it", 3, 2)
|
mocks[2].assert_called_once_with("do it", 3, 2)
|
||||||
self.assertIn("=== cycle 4 ===", sys.stdout.getvalue())
|
self.assertIn("=== cycle 4 ===", sys.stdout.getvalue())
|
||||||
mocks[3].side_effect = ["claude exited 3"] * 3
|
mocks[3].side_effect = ["claude exited 3"] * 3
|
||||||
stack.enter_context(unittest.mock.patch("time.sleep"))
|
stack.enter_context(unittest.mock.patch.object(sys, "argv", ["loop-claude", loop.RELOAD_FLAG, "3", "0", "do it"]))
|
||||||
|
stack.enter_context(unittest.mock.patch.object(sys, "stderr", io.StringIO()))
|
||||||
|
sleep = stack.enter_context(unittest.mock.patch("time.sleep"))
|
||||||
with self.assertRaises(SystemExit) as stopped:
|
with self.assertRaises(SystemExit) as stopped:
|
||||||
loop.main()
|
loop.main()
|
||||||
|
self.assertIn("the worker failed: claude exited 3 - retrying in a minute", sys.stderr.getvalue())
|
||||||
|
self.assertEqual(sleep.call_count, 2)
|
||||||
self.assertEqual(stopped.exception.code, "the worker failed three times running: claude exited 3")
|
self.assertEqual(stopped.exception.code, "the worker failed three times running: claude exited 3")
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user