Files
core/tests/test_server_health.py
Untone bc8447a444
Some checks failed
Deploy on push / deploy (push) Failing after 2m0s
citesting-fix1
2025-08-17 11:37:55 +03:00

88 lines
3.2 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
#!/usr/bin/env python3
"""
Тест здоровья серверов для CI
"""
import time
import requests
import pytest
def test_backend_health():
"""Проверяем здоровье бэкенда"""
max_retries = 10
for attempt in range(1, max_retries + 1):
try:
response = requests.get("http://localhost:8000/", timeout=10)
if response.status_code == 200:
print(f"✅ Бэкенд готов (попытка {attempt})")
return
except requests.exceptions.RequestException as e:
print(f"⚠️ Попытка {attempt}/{max_retries}: Бэкенд не готов - {e}")
if attempt < max_retries:
time.sleep(3)
else:
pytest.fail(f"Бэкенд не готов после {max_retries} попыток")
def test_frontend_health():
"""Проверяем здоровье фронтенда"""
max_retries = 10
for attempt in range(1, max_retries + 1):
try:
response = requests.get("http://localhost:3000/", timeout=10)
if response.status_code == 200:
print(f"✅ Фронтенд готов (попытка {attempt})")
return
except requests.exceptions.RequestException as e:
print(f"⚠️ Попытка {attempt}/{max_retries}: Фронтенд не готов - {e}")
if attempt < max_retries:
time.sleep(3)
else:
pytest.fail(f"Фронтенд не готов после {max_retries} попыток")
def test_graphql_endpoint():
"""Проверяем доступность GraphQL endpoint"""
try:
response = requests.post(
"http://localhost:8000/graphql",
headers={"Content-Type": "application/json"},
json={"query": "{ __schema { types { name } } }"},
timeout=15
)
if response.status_code == 200:
print("✅ GraphQL endpoint доступен")
return
else:
pytest.fail(f"GraphQL endpoint вернул статус {response.status_code}")
except requests.exceptions.RequestException as e:
pytest.fail(f"GraphQL endpoint недоступен: {e}")
def test_admin_panel_access():
"""Проверяем доступность админ-панели"""
try:
response = requests.get("http://localhost:3000/admin", timeout=15)
if response.status_code == 200:
print("✅ Админ-панель доступна")
return
else:
pytest.fail(f"Админ-панель вернула статус {response.status_code}")
except requests.exceptions.RequestException as e:
pytest.fail(f"Админ-панель недоступна: {e}")
if __name__ == "__main__":
print("🧪 Проверяем здоровье серверов...")
try:
test_backend_health()
test_frontend_health()
test_graphql_endpoint()
test_admin_panel_access()
print("Все серверы здоровы!")
except Exception as e:
print(f"❌ Ошибка проверки здоровья: {e}")
exit(1)