Spaces:
Paused
Paused
Download tests/test_infra.py from TeamError404/nexus: direct link, hf CLI and curl.
- Browser
- Download file 1.56 kB
-
https://huggingface.co/spaces/TeamError404/nexus/resolve/main/tests/test_infra.py
- Command line
-
hf download hf://spaces/TeamError404/nexus/tests/test_infra.py
-
curl -L -o test_infra.py https://huggingface.co/spaces/TeamError404/nexus/resolve/main/tests/test_infra.py
1.56 kB
| import pytest | |
| from httpx import AsyncClient | |
| import time | |
| from core.config import get_settings | |
| 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 | |
| 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() | |
| 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 | |