- carry the lab 2 solution over and plan lab 3 (PLAN.md, OpenSpec change instance-id-idempotency) - rename the compose project to mtusi-lab3 and the image to :lab3 - add X-Instance-Id to every response and instance_id to every log record ([app] instance_id, hostname by default) - require Idempotency-Key on POST messages: keys table in Postgres, key and message in one transaction, replay returns the same 201, another body gets 409, TTL from [idempotency] ttl_seconds - send the key from student-tests, k6 scenarios and the skill driver; add idempotency, X-Instance-Id, key race and fault tests Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
38 lines
1.4 KiB
Python
38 lines
1.4 KiB
Python
"""Спек `data-storage`.
|
|
|
|
Гонки — в `test_race.py`; рестарт, отказы БД и пул — исключения в
|
|
`spec_coverage.py`.
|
|
"""
|
|
|
|
import pytest
|
|
|
|
from api_client import API, Actor, Api
|
|
from contract import assert_ok
|
|
|
|
|
|
@pytest.mark.spec("data-storage", "Созданное видно сразу")
|
|
def test_created_user_visible_at_once(api: Api) -> None:
|
|
for _ in range(5):
|
|
actor = api.register()
|
|
resp = api.request("GET", f"{API}/users/me", actor=actor)
|
|
assert assert_ok(resp, 200, "User") == actor.user
|
|
|
|
|
|
@pytest.mark.spec("data-storage", "Порядок участников")
|
|
def test_member_order_kept(api: Api, alice: Actor, bob: Actor) -> None:
|
|
# порядок [bob, alice] из запроса не совпадает с порядком регистрации;
|
|
# «в том числе после рестарта» — evidence/storage/restart.md
|
|
created = api.create_chat(bob, alice, title="Порядок участников")
|
|
expected = [bob.id, alice.id]
|
|
assert created["member_ids"] == expected
|
|
|
|
resp = api.request("GET", f"{API}/chats/{created['id']}", actor=alice)
|
|
assert assert_ok(resp, 200, "Chat")["member_ids"] == expected
|
|
|
|
listed = {
|
|
chat["id"]: chat["member_ids"]
|
|
for page in api.chat_pages(alice)
|
|
for chat in page["items"]
|
|
}
|
|
assert listed[created["id"]] == expected
|