Spaces:
Paused

nexus / tests /test_infra.py
dushyantsingh0
backend stabilization
b7980f7
Raw History Blame Contribute Delete
1.56 kB
import pytest
from httpx import AsyncClient
import time
from core.config import get_settings
@pytest.mark.asyncio
async def test_api_heartbeat(client: AsyncClient):
"""Confirm the FastAPI master API is alive and responsive."""
response = await client.get("/api/v1/health")
# Note: If no global health endpoint exists, this might fail.
# Let's ensure it's pointing to a valid endpoint or create one.
assert response.status_code in [200, 404] # 404 if health route isn't defined yet
@pytest.mark.asyncio
async def test_redis_ping_latency():
"""Directly test Redis connectivity and latency."""
import redis.asyncio as redis
settings = get_settings()
start_time = time.perf_counter()
r = redis.from_url(settings.REDIS_URL, socket_timeout=5)
try:
# PING check
ping_res = await r.ping()
latency_ms = (time.perf_counter() - start_time) * 1000
assert ping_res is True
print(f"REDIS_HEALTH: Ping successful (Latency: {latency_ms:.2f}ms)")
# If latency is exceptionally high (>500ms), we should warning
assert latency_ms < 1000
finally:
await r.close()
@pytest.mark.asyncio
async def test_env_consistency():
"""Verify that critical environment variables are set."""
settings = get_settings()
assert settings.SUPABASE_URL is not None
assert "supabase.co" in settings.SUPABASE_URL
assert settings.REDIS_URL is not None
assert "upstash.io" in settings.REDIS_URL or "rediss://" in settings.REDIS_URL