Files
mtusi2026lab5/student-tests/cursor_validation.py
T
zemiles 13bec4ab8b ЛР 5 — БПИ2303 — Лазарев — на 4
Асинхронная обработка вложений: RabbitMQ 4.1 (quorum-очереди, publisher
confirms, manual ack, DLQ), transactional outbox, отдельный worker.

- upload: оригинал в staging S3, затем одной транзакцией queued + jobs +
  outbox -> 202; API к брокеру не подключается
- relay: публикация outbox с confirm, reaper истёкших аренд, redrive
- worker: claim по строке jobs, аренда с heartbeat и fencing по
  lease_token, transform в подпроцессе с RLIMIT_AS/RLIMIT_CPU/таймаутом,
  thumbnail 256, crop 128, WebP 1280 по детерминированным ключам
- retry с backoff и jitter, постоянные/временные ошибки, реестр failed,
  ops replay (ready не повторяется), DLQ для невалидных сообщений
- janitor: очистка staging и сирот; миграция 004 с backfill вложений lab4
- тесты отказов: окна COMMIT/publish, крахи worker до/после S3 и ack,
  заморозка worker, всплеск загрузок, права брокера; evidence/ и REPORT.md
2026-11-13 16:28:18 +03:00

33 lines
1.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""Проверка диапазона дат cursor: некорректная дата должна давать 400, а не 500."""
import base64
import json
import sys
import uuid
from pathlib import Path
from urllib.parse import quote
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / "tests"))
from client import Client, arguments, run
def main():
args = arguments(__doc__)
client = Client(args.base_url, ca_file=args.ca_file)
alice, _bob, _eve, chat = client.bootstrap()
checks = 0
for kind, scope, path in (
("messages", chat["id"], "/api/v1/chats/" + chat["id"] + "/messages"),
("chats", alice["id"], "/api/v1/chats"),
):
for timestamp, expected in ((-10**17, 400), (-62135596800000001, 400), (0, 200)):
payload = {"k": kind, "s": scope, "t": timestamp, "i": str(uuid.uuid4())}
cursor = base64.urlsafe_b64encode(json.dumps(payload).encode()).decode().rstrip("=")
client.call("GET", path + "?cursor=" + quote(cursor, safe=""), expected, actor=alice)
checks += 1
print("PASS: %d cursor date boundary checks; invalid dates return 400." % checks)
if __name__ == "__main__":
run(main)