test(pipeline): observe commit before acknowledgement in a warm process
This commit is contained in:
File diff suppressed because one or more lines are too long
@@ -86,8 +86,8 @@ def duplicate(job, count=5):
|
|||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
def inspect_effect(job, *, pending=False):
|
def effect_code(job, *, pending=False):
|
||||||
return inside(f"""with db.connection() as c:
|
return f"""with db.connection() as c:
|
||||||
j=c.execute('SELECT * FROM jobs WHERE id=%s',({job!r},)).fetchone()
|
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()
|
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']
|
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']
|
entry=item['message_id']
|
||||||
messages=queue.xrange(STREAM,min=entry,max=entry)
|
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)
|
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():
|
def main():
|
||||||
@@ -370,10 +387,31 @@ def main():
|
|||||||
stop("worker")
|
stop("worker")
|
||||||
a, j = upload()
|
a, j = upload()
|
||||||
marker = inject(j, phase, "wait")
|
marker = inject(j, phase, "wait")
|
||||||
start("worker")
|
# Start observation before the child timeout begins.
|
||||||
wait(lambda marker=marker: hit(marker))
|
# Polling through a new Python/Docker process at each
|
||||||
at_crash = inspect_effect(
|
# step can miss the actual COMMIT-before-ACK window.
|
||||||
j, pending=phase == "after_commit"
|
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"] == (
|
assert at_crash["job"]["state"] == (
|
||||||
"ready"
|
"ready"
|
||||||
@@ -413,6 +451,7 @@ def main():
|
|||||||
effect = inspect_effect(j)
|
effect = inspect_effect(j)
|
||||||
else:
|
else:
|
||||||
assert effect["job"]["attempt"] >= 2
|
assert effect["job"]["attempt"] >= 2
|
||||||
|
report.pop("active_case", None)
|
||||||
save(
|
save(
|
||||||
f"{phase}_sigkill_repeat_{repeat + 1}",
|
f"{phase}_sigkill_repeat_{repeat + 1}",
|
||||||
{"at_crash": at_crash, "effect": effect},
|
{"at_crash": at_crash, "effect": effect},
|
||||||
|
|||||||
Reference in New Issue
Block a user