94 lines
3.6 KiB
Python
94 lines
3.6 KiB
Python
#!/usr/bin/env python3
|
||
"""
|
||
Тест здоровья серверов для CI
|
||
"""
|
||
|
||
import time
|
||
import requests
|
||
import pytest
|
||
|
||
|
||
@pytest.mark.skip_ci
|
||
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} попыток")
|
||
|
||
|
||
@pytest.mark.skip_ci
|
||
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:
|
||
# В CI фронтенд может быть не запущен, поэтому не падаем
|
||
pytest.skip("Фронтенд не запущен (ожидаемо в некоторых CI средах)")
|
||
|
||
|
||
@pytest.mark.skip_ci
|
||
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}")
|
||
|
||
|
||
@pytest.mark.skip_ci
|
||
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:
|
||
# В CI фронтенд может быть не запущен, поэтому не падаем
|
||
pytest.skip("Админ-панель недоступна (фронтенд не запущен)")
|
||
|
||
|
||
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)
|