72 lines
2.6 KiB
Python
72 lines
2.6 KiB
Python
#!/usr/bin/env python3
|
|
"""COMMIT задания без publish: relay восстанавливает намерение из outbox."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import time
|
|
from datetime import datetime, timezone
|
|
from pathlib import Path
|
|
|
|
HERE = Path(__file__).resolve().parent
|
|
ROOT = HERE.parent
|
|
for candidate in (str(HERE), str(ROOT / "tests")):
|
|
if candidate not in sys.path:
|
|
sys.path.insert(0, candidate)
|
|
|
|
import job_control as jc # noqa: E402
|
|
|
|
PNG = (ROOT / "tests" / "fixtures" / "sample.png").read_bytes()
|
|
|
|
|
|
def now() -> str:
|
|
return datetime.now(timezone.utc).isoformat(timespec="seconds").replace("+00:00", "Z")
|
|
|
|
|
|
def main() -> int:
|
|
api = jc.client(timeout=20)
|
|
api.call("GET", "/health/ready", schema="Health")
|
|
alice, bob, eve, chat = api.bootstrap()
|
|
jc.scale("relay", 0)
|
|
jc.wait_service("relay", 0)
|
|
attachment = jc.upload(api, alice, chat, PNG)
|
|
report = jc.wait_job(api, alice, attachment["id"], "queued", timeout=30)
|
|
time.sleep(2.0)
|
|
before = jc.admin_json("show", "--attachment", attachment["id"])
|
|
pending = [row for row in before["outbox"] if row["published_at"] is None]
|
|
jc.scale("relay", 1)
|
|
jc.wait_service("relay", 1)
|
|
ready = jc.wait_attachment(api, alice, attachment["id"], "ready", timeout=120)
|
|
after = jc.admin_json("show", "--attachment", attachment["id"])
|
|
evidence = {
|
|
"started_at": None,
|
|
"scenario": "crash_between_commit_and_publish",
|
|
"attachment_id": attachment["id"],
|
|
"job_id": report["jobs"][0]["id"],
|
|
"relay_replicas_during_accept": 0,
|
|
"outbox_pending_before_relay": pending,
|
|
"status_before_relay": "queued",
|
|
"status_after_relay": ready["status"],
|
|
"job_attempts": after["jobs"][0]["attempts"],
|
|
"variants": [item["name"] for item in after["attachment"]["variants"]],
|
|
"outbox_after": after["outbox"],
|
|
"passed": (
|
|
len(pending) == 1
|
|
and ready["status"] == "ready"
|
|
and len(after["attachment"]["variants"]) == 3
|
|
),
|
|
"note": (
|
|
"API committed attachment+job+outbox and returned 202 while relay was "
|
|
"stopped. Starting relay published the exact pending outbox row and the "
|
|
"same job id completed; no second upload was needed."
|
|
),
|
|
}
|
|
output = ROOT / "evidence" / "outbox-gap.json"
|
|
output.write_text(json.dumps(evidence, ensure_ascii=False, indent=2, sort_keys=True), encoding="utf-8")
|
|
print(json.dumps(evidence, ensure_ascii=False, indent=2, sort_keys=True))
|
|
return 0 if evidence["passed"] else 1
|
|
|
|
|
|
if __name__ == "__main__":
|
|
raise SystemExit(main())
|