лабораторная работа 3

This commit is contained in:
2026-10-23 15:06:43 +03:00
parent 0ab3a341aa
commit eeee24d3d7
53 changed files with 2476 additions and 21 deletions
+23
View File
@@ -0,0 +1,23 @@
"""Lab3 balancing: X-Instance-Id is present and more than one replica serves."""
from __future__ import annotations
def test_instance_header_present_on_success(client, alice):
response = client.me(alice["token"])
assert response.status == 200, response.body
assert response.instance_id, "missing X-Instance-Id"
def test_instance_header_present_on_error(client):
response = client.request("GET", "/api/v1/users/me")
assert response.status == 401, response.body
assert response.instance_id, "error response missing X-Instance-Id"
def test_at_least_two_instances_seen_through_lb(client, alice):
seen = set()
for _ in range(60):
instance = client.me(alice["token"]).instance_id
if instance:
seen.add(instance)
assert len(seen) >= 2, f"expected >=2 API replicas behind the LB, saw {sorted(seen)}"