forked from mtusi2026/mtusi2026lab4
Carry over the lab 3 fixes made after 61c0c28
Bring the system changes of lab 3 from 61c0c28..72a1e57 onto the lab 4 code, resolving each conflict by meaning and keeping everything lab 4 added: - a message is posted with one SQL statement under the chat row lock, and the attachment links go into the same statement; a foreign key violation on the attachment link still answers 404 and leaves nothing behind. Text and the attachment list are checked before the write, an outsider gets 404 for both, as before the carry over; - the request pipeline counts the body bytes actually received against the limit of the route, so a chunked body over 1 MiB gets 413 and the upload route keeps its MAX_UPLOAD_BYTES limit; - a request cancelled at shutdown gets 503 unavailable in the contract format, the worker waits a second less than the rest of the shutdown budget, SHUTDOWN_TIMEOUT_SECONDS becomes 6 s and the stop hooks 7 s; - readiness sits behind a Readiness port with the draining flag in shared infrastructure, and the drain window is logged through Logger; - logout revokes through SessionRevocations and withdraws the mark when PostgreSQL rejects the delete; an empty cursor is 400; - EventBus.project is gone, the sweep test subscribes and waits on a queue; domain tests check attachment_list instead of Chat.post; - make up waits for every replica in the balancer, BASE_URL follows the lb port, the image is tagged by the compose project, retry-check and faults-evidence are added, detection runs three times, failover-each and rolling-update record the stand usage, CI checks numeric uids. down also takes the tools and reconcile profiles of lab 4. Track 1 tooling of lab 3 (scaling.py, its samplers, tools/ and the CPU pinning of api, lb, valkey and k6) stays out; stand-usage.sh queries the database size itself instead of the track 1 sampler. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01V1d3RLHNBBMA6UqBLLJv27
This commit is contained in:
co-authored by
Claude Opus 5.5
parent
7ac1a4a11b
commit
e927afdb09
@@ -1,4 +1,5 @@
|
||||
import asyncio
|
||||
import time
|
||||
from collections.abc import AsyncIterator
|
||||
from uuid import uuid4
|
||||
|
||||
@@ -18,6 +19,7 @@ from stand import (
|
||||
new_user,
|
||||
psql,
|
||||
report,
|
||||
restart_stack,
|
||||
started_at,
|
||||
timed,
|
||||
valkey,
|
||||
@@ -55,7 +57,8 @@ async def test_chat_creation_rolls_back_on_unknown_member(http: AsyncClient) ->
|
||||
json={"title": title, "member_ids": [alice["id"], str(uuid4())]},
|
||||
headers=bearer(token),
|
||||
)
|
||||
print(f"чат с несуществующим участником: {response.status_code}")
|
||||
code = response.json()["error"]["code"]
|
||||
print(f"чат с несуществующим участником: {response.status_code} {code}")
|
||||
assert response.status_code == 400
|
||||
assert response.json()["error"]["code"] == "invalid_request"
|
||||
assert psql("SELECT count(*) FROM chats WHERE title = :'title'", title=title) == "0"
|
||||
@@ -227,3 +230,43 @@ async def test_api_restart_keeps_session_without_extending_it(http: AsyncClient)
|
||||
print(f"expires_at при входе {session['expires_at']}, в БД после рестарта {stored}")
|
||||
assert me.status_code == 200
|
||||
assert stored.rstrip("Z").rstrip("0") == session["expires_at"].rstrip("Z").rstrip("0")
|
||||
|
||||
|
||||
async def test_full_restart_keeps_session_until_logout(http: AsyncClient) -> None:
|
||||
user, token = await enroll(http, "fullrestart")
|
||||
restart_stack()
|
||||
recovered = await wait_ready(http)
|
||||
me = await http.get("/api/v1/users/me", headers=bearer(token))
|
||||
logout = await http.delete("/api/v1/auth/sessions/current", headers=bearer(token))
|
||||
after = await http.get("/api/v1/users/me", headers=bearer(token))
|
||||
print(
|
||||
f"restart.sh: готовность через {recovered:.1f} с, прежний токен {me.status_code}, "
|
||||
f"выход {logout.status_code}, затем {after.status_code}"
|
||||
)
|
||||
assert me.json() == user
|
||||
assert logout.status_code == 204
|
||||
assert after.status_code == 401
|
||||
|
||||
|
||||
async def test_session_expires_after_restart_at_original_time(http: AsyncClient) -> None:
|
||||
user, token = await enroll(http, "shortrestart")
|
||||
expires_at = float(
|
||||
psql(
|
||||
"UPDATE sessions s SET expires_at = now() + interval '20 seconds' FROM users u "
|
||||
"WHERE u.id = s.user_id AND u.username = :'name' "
|
||||
"RETURNING extract(epoch FROM s.expires_at)",
|
||||
name=user["username"],
|
||||
).splitlines()[0]
|
||||
)
|
||||
compose("restart", "api")
|
||||
recovered = await wait_ready(http)
|
||||
fresh = await http.get("/api/v1/users/me", headers=bearer(token))
|
||||
await asyncio.sleep(max(0.0, expires_at - time.time()) + 0.5)
|
||||
stale = await http.get("/api/v1/users/me", headers=bearer(token))
|
||||
print(
|
||||
f"срок сессии сокращён до 20 с, рестарт api: готовность через {recovered:.1f} с, "
|
||||
f"до срока {fresh.status_code}, после срока {stale.status_code}"
|
||||
)
|
||||
assert fresh.status_code == 200
|
||||
assert stale.status_code == 401
|
||||
assert stale.headers["WWW-Authenticate"] == BEARER
|
||||
|
||||
Reference in New Issue
Block a user