forked from mtusi2026/mtusi2026lab4
Forward-port lab3 SQLAlchemy and Alembic foundation
Carry source f591fa64e525679a31c9db7f942d36c789e1a12f forward from 72a1e57. Preserve lab4 attachment transactions, reconciliation locks, quarantine, and existing schema data through verified legacy adoption. Keep report and evidence work in progress untouched.
This commit is contained in:
@@ -1,10 +1,11 @@
|
||||
import time
|
||||
from uuid import uuid4
|
||||
from uuid import UUID, uuid4
|
||||
|
||||
import asyncpg
|
||||
from httpx import AsyncClient
|
||||
from sqlalchemy import select
|
||||
|
||||
from conftest import DATABASE, actor, keyed, make_chat, register
|
||||
from conftest import actor, keyed, make_chat, register, sql_connection
|
||||
from messenger.messaging.infrastructure.postgres import ChatRow
|
||||
|
||||
|
||||
async def test_outsider_gets_404_on_chat(client: AsyncClient) -> None:
|
||||
@@ -106,16 +107,14 @@ async def test_outsider_does_not_wait_for_members_lock(client: AsyncClient) -> N
|
||||
alice = await register(client, "alice")
|
||||
eve = await register(client, "eve")
|
||||
chat = await make_chat(client, alice)
|
||||
holder = await asyncpg.connect(DATABASE["url"])
|
||||
try:
|
||||
async with holder.transaction():
|
||||
await holder.execute("SELECT 1 FROM chats WHERE id = $1 FOR UPDATE", chat["id"])
|
||||
started = time.perf_counter()
|
||||
response = await client.post(
|
||||
f"/api/v1/chats/{chat['id']}/messages", json={"text": "чужое"}, headers=keyed(eve)
|
||||
)
|
||||
elapsed = time.perf_counter() - started
|
||||
finally:
|
||||
await holder.close()
|
||||
async with sql_connection() as holder:
|
||||
await holder.execute(
|
||||
select(ChatRow.id).where(ChatRow.id == UUID(chat["id"])).with_for_update()
|
||||
)
|
||||
started = time.perf_counter()
|
||||
response = await client.post(
|
||||
f"/api/v1/chats/{chat['id']}/messages", json={"text": "чужое"}, headers=keyed(eve)
|
||||
)
|
||||
elapsed = time.perf_counter() - started
|
||||
assert response.status_code == 404
|
||||
assert elapsed < 0.5
|
||||
|
||||
Reference in New Issue
Block a user