diff --git a/bot_bottle/backend/smolmachines/smolvm.py b/bot_bottle/backend/smolmachines/smolvm.py index 570321f..bf911a8 100644 --- a/bot_bottle/backend/smolmachines/smolvm.py +++ b/bot_bottle/backend/smolmachines/smolvm.py @@ -32,7 +32,6 @@ from dataclasses import dataclass from pathlib import Path from typing import Mapping, Sequence -from ...log import die _SMOLVM = "smolvm" @@ -218,9 +217,13 @@ def wait_exec_ready(name: str, *, timeout: float = 5.0) -> None: break time.sleep(min(delay, remaining)) delay = min(delay * 2, 0.5) - die( - f"smolvm machine {name!r}: exec channel not ready after " - f"{timeout:.0f}s — VM may have failed to boot." + argv = ["smolvm", "machine", "exec", "--name", name, "--", "true"] + raise SmolvmError( + argv, + subprocess.CompletedProcess( + args=argv, returncode=-1, stdout="", + stderr=f"exec channel not ready after {timeout:.0f}s — VM may have failed to boot.", + ), ) diff --git a/tests/unit/test_smolmachines_smolvm.py b/tests/unit/test_smolmachines_smolvm.py index bb5ed5f..efc1c29 100644 --- a/tests/unit/test_smolmachines_smolvm.py +++ b/tests/unit/test_smolmachines_smolvm.py @@ -228,7 +228,7 @@ class TestWaitExecReady(unittest.TestCase): wait_exec_ready("vm-x") self.assertEqual(3, m.call_count) - def test_dies_on_timeout(self): + def test_raises_smolvm_error_on_timeout(self): # machine_exec always returns non-zero; monotonic advances past # the deadline after the first sleep so the loop exits. ticks = [0.0, 0.0, 10.0] # third call puts us past deadline @@ -236,13 +236,11 @@ class TestWaitExecReady(unittest.TestCase): return_value=SmolvmRunResult(1, "", "")), \ patch.object(smolvm_mod.time, "monotonic", side_effect=ticks), \ - patch.object(smolvm_mod.time, "sleep"), \ - patch.object(smolvm_mod, "die", - side_effect=SystemExit("die")) as die_mock: - with self.assertRaises(SystemExit): + patch.object(smolvm_mod.time, "sleep"): + with self.assertRaises(SmolvmError) as cm: wait_exec_ready("vm-x", timeout=5.0) - die_mock.assert_called_once() - self.assertIn("vm-x", die_mock.call_args.args[0]) + self.assertIn("vm-x", str(cm.exception)) + self.assertIn("not ready", str(cm.exception)) class TestIsAvailable(unittest.TestCase):