test(issue-50): c10 makes the same-second tie instead of timing it (reviews 98b31bb2 / 352066ec / 244b8072 F-B)
The live onboarding test asserted that the first job's wrapper registered in the same wall-clock second as the onboarding it had just placed at a second boundary. Process start-up has no sub-second contract, so the setup assertion failed now and then before any dispatch behaviour was checked. The test now stamps the onboarding record, which it owns and which nothing else depends on yet, with the job's created_at once that record exists; the stamp is written by atomic replace so a scanning wrapper never skips a half-written record. The lifecycle assertions and the fixed-id tie coverage in test_u2h are unchanged. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com>
This commit is contained in:
1 parent
6c99fedf40
commit
320aa9f7a0
1 file changed
+23
-10
@@ -522,30 +522,44 @@ def _onboarding(box: Box, ack: int) -> str:
|
|||||||
return a
|
return a
|
||||||
|
|
||||||
|
|
||||||
|
def _restamp(box: Box, jid: str, created_at: str) -> None:
|
||||||
|
"""Give a record the test owns another created_at, atomically: a wrapper
|
||||||
|
scanning the registry must never find the file half-written (an unreadable
|
||||||
|
record is skipped, which would let it through)."""
|
||||||
|
rec = box.record(jid)
|
||||||
|
rec["created_at"] = created_at
|
||||||
|
tmp = box.jobs / f"{jid}.json.tmp"
|
||||||
|
tmp.write_text(json.dumps(rec))
|
||||||
|
os.replace(tmp, box.jobs / f"{jid}.json")
|
||||||
|
|
||||||
|
|
||||||
def test_c10_a_pending_onboarding_within_its_ack_budget_blocks_the_session_past_the_signal_window(box):
|
def test_c10_a_pending_onboarding_within_its_ack_budget_blocks_the_session_past_the_signal_window(box):
|
||||||
# review 5a09a13f F-A: the onboarding and the first job are registered in
|
# review 5a09a13f F-A: the onboarding and the first job are registered in
|
||||||
# the same second (create registers, then injects; the job's wrapper
|
# the same second (create registers, then injects; the job's wrapper
|
||||||
# registers a moment later), where the FIFO's (created_at, job_id) once
|
# registers a moment later), where the FIFO's (created_at, job_id) once
|
||||||
# let a lower id pass the injected onboarding; the second job comes a
|
# let a lower id pass the injected onboarding. The tie is made, not timed
|
||||||
# different second
|
# (reviews 98b31bb2 / 352066ec / 244b8072 F-B): once the first job's record
|
||||||
while time.time() % 1 > 0.05:
|
# exists, A takes its created_at - A has no signal and no admission, and the
|
||||||
time.sleep(0.005)
|
# pane already holds its prompt, so nothing else depends on the stamp. The
|
||||||
t0 = time.time()
|
# second job comes a different second.
|
||||||
a = box.register(ack_timeout_sec=180)
|
a = box.register(ack_timeout_sec=180)
|
||||||
known = box.job_ids()
|
known = box.job_ids()
|
||||||
|
created = 0
|
||||||
for label in ("before", "after"):
|
for label in ("before", "after"):
|
||||||
if label == "after":
|
if label == "after":
|
||||||
time.sleep(max(0.0, t0 + 31.5 - time.time())) # A is now older than the signal window
|
time.sleep(max(0.0, created + 31.5 - time.time())) # A is now older than the signal window
|
||||||
proc = box.submit(prompt="work " + label, MAM_DISPATCH_WAIT_S="3")
|
proc = box.submit(prompt="work " + label, MAM_DISPATCH_WAIT_S="3")
|
||||||
if label == "before":
|
if label == "before":
|
||||||
prompt = box.herdr("agent", "prompt", SESSION, "Onboarding " + a)
|
prompt = box.herdr("agent", "prompt", SESSION, "Onboarding " + a)
|
||||||
assert prompt.returncode == 0, prompt.stdout + prompt.stderr
|
assert prompt.returncode == 0, prompt.stdout + prompt.stderr
|
||||||
b = box.wait_new_job(known)
|
b = box.wait_new_job(known)
|
||||||
known.add(b)
|
known.add(b)
|
||||||
print(label, "created", a, box.record(a)["created_at"], b, box.record(b)["created_at"],
|
|
||||||
"registered at +%.2fs" % (time.time() - t0))
|
|
||||||
if label == "before":
|
if label == "before":
|
||||||
assert box.record(b)["created_at"] == box.record(a)["created_at"], "the same-second tie this exercises"
|
_restamp(box, a, box.record(b)["created_at"])
|
||||||
|
created = calendar.timegm(time.strptime(box.record(a)["created_at"], "%Y-%m-%dT%H:%M:%SZ"))
|
||||||
|
print(label, "created", a, box.record(a)["created_at"], b, box.record(b)["created_at"],
|
||||||
|
"at +%.2fs" % (time.time() - created))
|
||||||
|
assert (box.record(b)["created_at"] > box.record(a)["created_at"]) == (label == "after"), label
|
||||||
rc, out, err = box.finish(proc)
|
rc, out, err = box.finish(proc)
|
||||||
assert rc == 5, (label, out + err)
|
assert rc == 5, (label, out + err)
|
||||||
rec = box.record(b)
|
rec = box.record(b)
|
||||||
@@ -553,7 +567,6 @@ def test_c10_a_pending_onboarding_within_its_ack_budget_blocks_the_session_past_
|
|||||||
assert a in err and "still has open jobs in the registry" in err and "stale open job" not in err, (label, err)
|
assert a in err and "still has open jobs in the registry" in err and "stale open job" not in err, (label, err)
|
||||||
assert b not in box.pane_text(), label
|
assert b not in box.pane_text(), label
|
||||||
assert box.record(a)["status"] == "pending" and "dispatch_wait_at" not in box.record(a), label
|
assert box.record(a)["status"] == "pending" and "dispatch_wait_at" not in box.record(a), label
|
||||||
created = calendar.timegm(time.strptime(box.record(a)["created_at"], "%Y-%m-%dT%H:%M:%SZ"))
|
|
||||||
assert 31 <= time.time() - created < 180, "the second answer came past the window, within the budget"
|
assert 31 <= time.time() - created < 180, "the second answer came past the window, within the budget"
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user