69 lines
2.7 KiB
Python
69 lines
2.7 KiB
Python
#!/usr/bin/env python3
|
|
"""Staging удаляется только после успешной фиксации результата."""
|
|
from __future__ import annotations
|
|
|
|
import json
|
|
import sys
|
|
import time
|
|
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 main() -> int:
|
|
api = jc.client(timeout=20)
|
|
api.call("GET", "/health/ready", schema="Health")
|
|
alice, bob, eve, chat = api.bootstrap()
|
|
# Worker остановлен: видно staging-объект до публикации результата.
|
|
jc.scale("worker", 0)
|
|
jc.wait_service("worker", 0)
|
|
attachment = jc.upload(api, alice, chat, PNG)
|
|
staging_before = jc.list_objects("staging/%s" % attachment["id"])
|
|
final_before = jc.list_objects("final/%s/" % attachment["id"])
|
|
jc.scale("worker", 1)
|
|
jc.wait_service("worker", 1)
|
|
ready = jc.wait_attachment(api, alice, attachment["id"], "ready", timeout=120)
|
|
time.sleep(1.0)
|
|
staging_after = jc.list_objects("staging/%s" % attachment["id"])
|
|
final_after = jc.list_objects("final/%s/" % attachment["id"])
|
|
report = jc.admin_json("show", "--attachment", attachment["id"])
|
|
evidence = {
|
|
"scenario": "staging_cleanup_after_commit",
|
|
"attachment_id": attachment["id"],
|
|
"staging_before_ready": staging_before,
|
|
"final_before_ready": final_before,
|
|
"staging_after_ready": staging_after,
|
|
"final_after_ready": final_after,
|
|
"attachment_status": ready["status"],
|
|
"staging_key_in_db": report["attachment"]["staging_key"],
|
|
"original_key_in_db": report["attachment"]["object_key"],
|
|
"variants": [item["name"] for item in report["attachment"]["variants"]],
|
|
"passed": (
|
|
len(staging_before) == 1
|
|
and len(staging_after) == 0
|
|
and len(final_after) == 4
|
|
and ready["status"] == "ready"
|
|
),
|
|
"note": (
|
|
"The original was visible under the staging prefix before commit. "
|
|
"After the ready commit, worker deleted it; final prefix contains the "
|
|
"original plus exactly three variants."
|
|
),
|
|
}
|
|
output = ROOT / "evidence" / "staging-cleanup.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())
|