ЛР5: асинхронная обработка вложений (RabbitMQ + worker), transactional outbox, варианты, трек 5.1

This commit is contained in:
2026-11-20 16:57:31 +03:00
parent 276dbdad8a
commit cbaadb7636
67 changed files with 5603 additions and 20 deletions
+34
View File
@@ -0,0 +1,34 @@
"""Grade-4 integrity checks: registration race and composite-op rollback."""
from __future__ import annotations
import concurrent.futures
import os
def test_concurrent_duplicate_username_single_winner(client):
username = "race_dup_" + os.urandom(4).hex()
password = "T3st-" + os.urandom(8).hex()
def register(_):
return client.register(username, password).status
with concurrent.futures.ThreadPoolExecutor(max_workers=5) as pool:
statuses = list(pool.map(register, range(5)))
assert statuses.count(201) == 1, statuses
assert statuses.count(409) == 4, statuses
def test_failed_chat_creation_rolls_back(client, alice):
def chats_count():
return len(client.request("GET", "/api/v1/chats?limit=100", token=alice["token"]).json["items"])
before = chats_count()
unknown = "00000000-0000-4000-8000-000000000000"
response = client.create_chat(alice["token"], [alice["id"], unknown], title="should-rollback")
assert response.status == 400, response.body
after = chats_count()
assert after == before, "failed composite operation left a partial chat"
listed = client.request("GET", "/api/v1/chats?limit=100", token=alice["token"]).json["items"]
assert all(item["title"] != "should-rollback" for item in listed)