control: the operation record takes a long start wait too, and the tests walk the whole CLI path (#3459 #4191)
A local build of the previous commit got further and said `direct runtime intent has an invalid timeout`. A start wait is
checked three times before the engine is reached, and 27cbbfe6 raised only the runtime's: management.runtime_action (fixed in
the previous commit), journal._validate_direct_intent, and runtime.start itself. The record is written before the start runs,
so its own (0, 600) for runtime.start and (1, 600) for startup_wait_s stopped a long wait that the layer above had just
accepted.
The record now reads both ceilings from the runtime that runs the wait, the way the CLI validator does. A wait above them is
still refused, and stop and verify keep their own 600 s, which is what runtime.stop and runtime.verify take.
The tests are the reason this was found twice by hand instead of once here: the CLI test from the previous commit faked
runtime.start, so it stopped at the first gate and passed while the record still refused the wait. One test now walks
management -> journal -> runtime.start with only the engine itself faked, at 300, 600, 601 and MAX_START_WAIT, and says which
wait failed to arrive; another pins each kind's ceiling on the record directly. Reverting the journal change fails three of
them with the quoted message; with it, all four pass. StartWaitLimit keeps its records in a scratch folder.
This commit is contained in:
1 parent
5af539691d
commit
293044e561
2 files changed
+66
-15
No files matched your search
@@ -130,9 +130,14 @@ def _validate_direct_intent(kind: str, intent: object) -> dict:
|
||||
for key in ("if_owner_id", "if_instance_id"))):
|
||||
raise ProfileError("direct benchmark intent is invalid", 5)
|
||||
elif kind.startswith("runtime."):
|
||||
ranges = {"wait_s": (0, 600) if kind == "runtime.start" else
|
||||
# The waits are bounded by the runtime that runs them, so the ceiling is read from it (#3949): a start or a
|
||||
# restart may wait for a big model up to MAX_START_WAIT. Repeating the number here is what broke a long start
|
||||
# twice over - the CLI validator and this record both stopped it at 600 s on their way to the runtime.
|
||||
from strata_control import runtime as _runtime
|
||||
start_wait_max = int(_runtime.MAX_START_WAIT)
|
||||
ranges = {"wait_s": (0, start_wait_max) if kind == "runtime.start" else
|
||||
(1, 1800) if kind == "runtime.restart" else (1, 600),
|
||||
"shutdown_timeout_s": (0, 300), "startup_wait_s": (1, 600)}
|
||||
"shutdown_timeout_s": (0, 300), "startup_wait_s": (1, start_wait_max)}
|
||||
for key in set(intent) - {"expected_profile_revision", "expected_source_sha256",
|
||||
"expected_owner_id", "expected_instance_id", "load",
|
||||
"allow_source_switch", "allow_source_migration"}:
|
||||
|
||||
@@ -1309,6 +1309,18 @@ class RuntimeTests(unittest.TestCase):
|
||||
|
||||
|
||||
class StartWaitLimit(unittest.TestCase):
|
||||
def setUp(self):
|
||||
# A start writes an operation record before the engine runs, so these tests keep their records (and any profile
|
||||
# lookup) in a scratch folder rather than in the person's own state.
|
||||
temp = tempfile.TemporaryDirectory(prefix="strata-start-wait-test-")
|
||||
self.addCleanup(temp.cleanup)
|
||||
root = Path(temp.name)
|
||||
(root / "profiles").mkdir()
|
||||
env = mock.patch.dict(os.environ, {"STRATA_PROFILE_DIR": str(root / "profiles"),
|
||||
"STRATA_RUNTIME_DIR": str(root / "runtime")})
|
||||
env.start()
|
||||
self.addCleanup(env.stop)
|
||||
|
||||
def test_a_start_may_wait_up_to_thirty_minutes_for_a_big_model(self): # #3949
|
||||
from strata_control import runtime as rt, profiles as pr
|
||||
self.assertEqual(rt.MAX_START_WAIT, 1800)
|
||||
@@ -1318,22 +1330,56 @@ class StartWaitLimit(unittest.TestCase):
|
||||
with self.assertRaisesRegex(pr.ProfileError, "reached"):
|
||||
rt.start("x", wait=1800)
|
||||
|
||||
def test_the_cli_start_wait_takes_the_same_ceiling_as_the_runtime(self): # #3459 #4191
|
||||
# The desktop app starts models through `strata runtime start --wait`, which management validates on its way to
|
||||
# runtime.start. When only the runtime's ceiling was raised, every long start was refused here with
|
||||
# "start wait must be finite seconds in 0..600" before the engine was even reached.
|
||||
def test_a_long_start_wait_reaches_the_runtime_through_the_cli(self): # #3459 #4191
|
||||
# The desktop app starts models through `strata runtime start --wait`, and that wait is checked three times before
|
||||
# the engine is reached: by management, by the operation record, and by the runtime itself. When only the runtime's
|
||||
# ceiling was raised (#3949), a long start died at each of the first two with
|
||||
# "start wait must be finite seconds in 0..600" / "direct runtime intent has an invalid timeout". So this walks the
|
||||
# whole way with only the engine itself faked: any layer that still carries the old 600 s shows up here.
|
||||
from strata_control import journal as jn, management as mg, profiles as pr, runtime as rt
|
||||
revision = "0123456789abcdef"
|
||||
for wait in (300, 600, 601, rt.MAX_START_WAIT):
|
||||
reached = {}
|
||||
with mock.patch.object(rt, "_name", lambda name: name), \
|
||||
mock.patch.object(mg.profiles, "load", lambda name: ("src", revision)), \
|
||||
mock.patch.object(rt, "start", lambda name, **kw: (reached.update(kw),
|
||||
{"ok": True, "state": "ready", "profile": name})[1]):
|
||||
result = mg.runtime_action("start", "demo", wait=wait, shutdown_timeout=15)
|
||||
self.assertEqual(result["state"], "ready")
|
||||
self.assertEqual(reached["wait"], float(wait),
|
||||
f"a start asked for {wait} s did not reach runtime.start with it")
|
||||
|
||||
def test_a_start_wait_above_the_runtime_ceiling_is_named_by_the_runtime(self): # #3459 #4191
|
||||
from strata_control import management as mg, profiles as pr, runtime as rt
|
||||
for wait in (601, rt.MAX_START_WAIT):
|
||||
with self.subTest(wait=wait), mock.patch.object(rt, "_name", side_effect=pr.ProfileError("reached")):
|
||||
with self.assertRaisesRegex(pr.ProfileError, "reached"):
|
||||
mg.runtime_action("start", "x", wait=wait)
|
||||
passthrough = mock.patch.object(rt, "_name", side_effect=lambda name: name)
|
||||
with passthrough:
|
||||
revision = "0123456789abcdef"
|
||||
with mock.patch.object(rt, "_name", lambda name: name), \
|
||||
mock.patch.object(mg.profiles, "load", lambda name: ("src", revision)):
|
||||
with self.assertRaisesRegex(pr.ProfileError, f"start wait must be finite seconds in 0..{rt.MAX_START_WAIT}"):
|
||||
mg.runtime_action("start", "x", wait=rt.MAX_START_WAIT + 1)
|
||||
with passthrough:
|
||||
mg.runtime_action("start", "demo", wait=rt.MAX_START_WAIT + 1, shutdown_timeout=15)
|
||||
with self.assertRaisesRegex(pr.ProfileError, f"startup wait must be finite seconds in 1..{rt.MAX_START_WAIT}"):
|
||||
mg.runtime_action("restart", "x", startup_wait=rt.MAX_START_WAIT + 1)
|
||||
mg.runtime_action("restart", "demo", startup_wait=rt.MAX_START_WAIT + 1,
|
||||
if_owner_id="0" * 32, if_instance_id="0" * 32)
|
||||
|
||||
def test_the_operation_record_takes_the_runtimes_own_start_ceiling(self):
|
||||
# The record is written before the start runs, so a ceiling kept here would stop a long wait no matter what the
|
||||
# two validators above allow. Waits that are not a start or a restart keep their own 600 s.
|
||||
from strata_control import journal as jn, profiles as pr, runtime as rt
|
||||
for kind, intent, allowed in (
|
||||
("runtime.start", {"wait_s": rt.MAX_START_WAIT, "shutdown_timeout_s": 15}, True),
|
||||
("runtime.start", {"wait_s": rt.MAX_START_WAIT + 1, "shutdown_timeout_s": 15}, False),
|
||||
("runtime.restart", {"wait_s": 1000, "startup_wait_s": rt.MAX_START_WAIT,
|
||||
"expected_profile_revision": "0" * 16,
|
||||
"expected_owner_id": "0" * 32, "expected_instance_id": "0" * 32,
|
||||
"allow_source_switch": False, "allow_source_migration": False,
|
||||
"expected_source_sha256": "0" * 64}, True),
|
||||
("runtime.stop", {"wait_s": rt.MAX_START_WAIT}, False),
|
||||
("runtime.verify", {"wait_s": rt.MAX_START_WAIT, "load": False}, False)):
|
||||
with self.subTest(kind=kind, wait=intent["wait_s"]):
|
||||
if allowed:
|
||||
jn._validate_direct_intent(kind, dict(intent))
|
||||
else:
|
||||
with self.assertRaisesRegex(pr.ProfileError, "invalid timeout"):
|
||||
jn._validate_direct_intent(kind, dict(intent))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
|
||||
Reference in new issue
Block a user