Forward the lab 5 foundation while preserving lab 6 telemetry
Source: immutable lab5 snapshot f88e9ba43cdfd7eb6a5a7ae5feb4247b4e820071; forward the allowed diff from 64d5c67. Carry SQLAlchemy, Alembic, reliability fixes, versioned jobs, infrastructure and student tests without changing protected coursework files.
Validation: make check, validate, lint; 515 student tests passed with one Linux-only skip; public smoke with telemetry enabled and repeat migration passed. Stop the owned stack and retain volumes. Preserve the existing OTel work in progress; grade implementation remains a separate phase.
This commit is contained in:
@@ -1,10 +1,13 @@
|
||||
import asyncio
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from urllib.parse import quote
|
||||
from uuid import uuid4
|
||||
|
||||
import pytest
|
||||
from httpx import AsyncClient
|
||||
|
||||
from conftest import PASSWORD, actor, keyed, make_chat, register
|
||||
from messenger.shared.infrastructure.clock import MonotonicUtcClock
|
||||
|
||||
CLIENTS = 10
|
||||
PER_CLIENT = 10
|
||||
@@ -60,6 +63,22 @@ async def test_hundred_messages_from_ten_clients(client: AsyncClient) -> None:
|
||||
assert len(set(stamps)) == TOTAL, "created_at внутри чата обязан строго возрастать"
|
||||
|
||||
|
||||
async def test_history_follows_the_clock_but_never_moves_back(
|
||||
monkeypatch: pytest.MonkeyPatch, client: AsyncClient
|
||||
) -> None:
|
||||
alice = await register(client, "alice")
|
||||
chat = await make_chat(client, alice)
|
||||
base = datetime.now(UTC) + timedelta(minutes=10)
|
||||
stamps = []
|
||||
for moment in (base, base - timedelta(minutes=5), base + timedelta(seconds=5)):
|
||||
monkeypatch.setattr(MonotonicUtcClock, "now", lambda _self, moment=moment: moment)
|
||||
response = await client.post(
|
||||
f"/api/v1/chats/{chat['id']}/messages", json={"text": "часы"}, headers=keyed(alice)
|
||||
)
|
||||
stamps.append(datetime.fromisoformat(response.json()["created_at"]))
|
||||
assert stamps == [base, base + timedelta(microseconds=1), base + timedelta(seconds=5)]
|
||||
|
||||
|
||||
async def test_parallel_registration_keeps_username_unique(client: AsyncClient) -> None:
|
||||
body = {"username": f"race_{uuid4().hex[:12]}", "display_name": "Гонка", "password": PASSWORD}
|
||||
responses = await asyncio.gather(*(client.post("/api/v1/users", json=body) for _ in range(20)))
|
||||
|
||||
Reference in New Issue
Block a user