forked from mtusi2026/mtusi2026lab3
24 lines
862 B
Python
24 lines
862 B
Python
"""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)}"
|