test(pipeline): observe commit before acknowledgement in a warm process

This commit is contained in:
2026-11-20 19:22:26 +03:00
parent 39dd361da2
commit 8f1b672604
2 changed files with 9817 additions and 7 deletions
File diff suppressed because one or more lines are too long
+46 -7
View File
@@ -86,8 +86,8 @@ def duplicate(job, count=5):
)
def inspect_effect(job, *, pending=False):
return inside(f"""with db.connection() as c:
def effect_code(job, *, pending=False):
return f"""with db.connection() as c:
j=c.execute('SELECT * FROM jobs WHERE id=%s',({job!r},)).fetchone()
v=c.execute('SELECT name,object_key,sha256,size_bytes FROM attachment_variants WHERE attachment_id=%s AND pipeline_version=%s ORDER BY name',(j['attachment_id'],j['pipeline_version'])).fetchall()
p=c.execute('SELECT count(*) n FROM effect_publications WHERE attachment_id=%s AND pipeline_version=%s',(j['attachment_id'],j['pipeline_version'])).fetchone()['n']
@@ -99,7 +99,24 @@ if {pending!r}:
entry=item['message_id']
messages=queue.xrange(STREAM,min=entry,max=entry)
if messages and json.loads(messages[0][1].get('job','{{}}')).get('job_id')==str(j['id']): pending_entries.append(entry)
print(json.dumps({{'job':j,'variants':v,'publications':p,'physical_keys':keys,'events':e,'pending_stream_entries':pending_entries}},default=str))""")
print(json.dumps({{'job':j,'variants':v,'publications':p,'physical_keys':keys,'events':e,'pending_stream_entries':pending_entries}},default=str))"""
def inspect_effect(job, *, pending=False):
return inside(effect_code(job, pending=pending))
def observe_fault(job, marker, *, pending=False):
code = f"""from src.pipeline import event
with db.connection() as c: event(c,UUID({job!r}),'crash_observer_ready')
end=time.monotonic()+60
while True:
with db.connection() as c: hit=c.execute('SELECT hit_at FROM pipeline_faults WHERE id=%s',({marker},)).fetchone()['hit_at']
if hit: break
if time.monotonic()>end: raise TimeoutError('Crash hook not hit')
time.sleep(.025)
"""
return inside(code + effect_code(job, pending=pending))
def main():
@@ -370,10 +387,31 @@ def main():
stop("worker")
a, j = upload()
marker = inject(j, phase, "wait")
start("worker")
wait(lambda marker=marker: hit(marker))
at_crash = inspect_effect(
j, pending=phase == "after_commit"
# Start observation before the child timeout begins.
# Polling through a new Python/Docker process at each
# step can miss the actual COMMIT-before-ACK window.
with ThreadPoolExecutor(max_workers=1) as hot:
observer = hot.submit(
observe_fault,
j,
marker,
pending=phase == "after_commit",
)
wait(
lambda j=j: inside(
f"with db.connection() as c: n=c.execute(\"SELECT count(*) n FROM pipeline_events WHERE job_id=%s AND event='crash_observer_ready'\",({j!r},)).fetchone()['n']\nprint(json.dumps(n>0))"
)
)
start("worker")
at_crash = observer.result(timeout=60)
report["active_case"] = {
"phase": phase,
"repeat": repeat + 1,
"at_crash": at_crash,
}
output.write_text(
json.dumps(report, ensure_ascii=False, indent=2)
+ "\n"
)
assert at_crash["job"]["state"] == (
"ready"
@@ -413,6 +451,7 @@ def main():
effect = inspect_effect(j)
else:
assert effect["job"]["attempt"] >= 2
report.pop("active_case", None)
save(
f"{phase}_sigkill_repeat_{repeat + 1}",
{"at_crash": at_crash, "effect": effect},