выполнение лр2 на 4
Skeleton contracts / contracts (pull_request) Failing after 37s

This commit is contained in:
Ilya
2026-10-09 12:44:56 +03:00
parent e914e384fc
commit 13fa1852cb
30 changed files with 585 additions and 238 deletions
+4 -14
View File
@@ -1,11 +1,4 @@
#!/usr/bin/env python3
"""Valkey's role and failures of each dependency. STOPS AND STARTS containers of this stack.
- Valkey really caches sessions and holds logout tombstones.
- Valkey down: API keeps working (cache bypassed), readiness stays 200.
- PostgreSQL down: bounded 503 quickly, readiness 503, liveness 200; an unverifiable
token is never accepted; no token is still 401. Recovery after start.
"""
import time
from stack import BASE_URL, Client, Failure, check, compose, main_wrapper, ok, valkey
@@ -27,7 +20,6 @@ def main():
alice, bob, _eve, chat = c.bootstrap()
history = "/api/v1/chats/" + chat["id"] + "/messages"
# Role of Valkey: a session lookup fills the cache, logout leaves a tombstone.
before = int(valkey("DBSIZE"))
c.call("GET", "/api/v1/users/me", actor=alice, schema="User")
keys = valkey("--scan", "--pattern", "session:*").split()
@@ -41,13 +33,12 @@ def main():
check(tombstones, "logout must leave a 'revoked' tombstone in the cache")
ok("Valkey caches sessions with TTL<=300s and keeps logout tombstones")
# Valkey down -> the API bypasses the cache, PostgreSQL stays the source of truth.
try:
compose("stop", "valkey")
c.call("GET", "/health/ready", 200)
c.call("GET", "/api/v1/users/me", actor=alice, schema="User")
c.message(bob, chat, "без кэша")
c.call("GET", "/api/v1/users/me", 401, actor=temp) # revoked in PostgreSQL too
c.call("GET", "/api/v1/users/me", 401, actor=temp)
start = time.monotonic()
for _ in range(10):
c.call("GET", history + "?limit=1", actor=alice, schema="MessagePage")
@@ -57,8 +48,7 @@ def main():
finally:
compose("start", "valkey")
# PostgreSQL down -> bounded 503, never anonymous access.
fresh = c.user("dbdown") # token never looked up yet: not in the cache
fresh = c.user("dbdown")
try:
compose("stop", "postgres")
c.call("GET", "/health/live", 200)
@@ -67,8 +57,8 @@ def main():
check(r["json"]["error"]["code"] == "unavailable", "readiness must report unavailable")
c.call("GET", "/api/v1/chats", 503, actor=alice)
c.call("POST", history, 503, actor=alice, body={"text": "в никуда"})
c.call("GET", "/api/v1/users/me", 503, actor=fresh) # cannot verify -> not trusted
c.call("GET", "/api/v1/users/me", 401) # no credentials at all
c.call("GET", "/api/v1/users/me", 503, actor=fresh)
c.call("GET", "/api/v1/users/me", 401)
elapsed = time.monotonic() - start
check(elapsed < 20, "errors must be bounded in time (%.1fs)" % elapsed)
ok("PostgreSQL stopped: live=200, ready/business=503 in %.1fs total, unverified token not trusted" % elapsed)