-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
/
Copy pathtest_health.py
116 lines (90 loc) · 3.2 KB
/
test_health.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
# What this tests?
## Tests /health + /routes endpoints.
import pytest
import asyncio
import aiohttp
async def health(session, call_key):
url = "http://0.0.0.0:4000/health"
headers = {
"Authorization": f"Bearer {call_key}",
"Content-Type": "application/json",
}
async with session.get(url, headers=headers) as response:
status = response.status
response_text = await response.text()
print(f"Response (Status code: {status}):")
print(response_text)
print()
if status != 200:
raise Exception(f"Request did not return a 200 status code: {status}")
return await response.json()
async def generate_key(session):
url = "http://0.0.0.0:4000/key/generate"
headers = {"Authorization": "Bearer sk-1234", "Content-Type": "application/json"}
data = {
"models": ["gpt-4", "text-embedding-ada-002", "dall-e-2"],
"duration": None,
}
async with session.post(url, headers=headers, json=data) as response:
status = response.status
response_text = await response.text()
print(response_text)
print()
if status != 200:
raise Exception(f"Request did not return a 200 status code: {status}")
return await response.json()
@pytest.mark.asyncio
async def test_health():
"""
- Call /health
"""
async with aiohttp.ClientSession() as session:
# as admin #
all_healthy_models = await health(session=session, call_key="sk-1234")
total_model_count = (
all_healthy_models["healthy_count"] + all_healthy_models["unhealthy_count"]
)
assert total_model_count > 0
@pytest.mark.asyncio
async def test_health_readiness():
"""
Check if 200
"""
async with aiohttp.ClientSession() as session:
url = "http://0.0.0.0:4000/health/readiness"
async with session.get(url) as response:
status = response.status
response_json = await response.json()
print(response_json)
assert "litellm_version" in response_json
assert "status" in response_json
if status != 200:
raise Exception(f"Request did not return a 200 status code: {status}")
@pytest.mark.asyncio
async def test_health_liveliness():
"""
Check if 200
"""
async with aiohttp.ClientSession() as session:
url = "http://0.0.0.0:4000/health/liveliness"
async with session.get(url) as response:
status = response.status
response_text = await response.text()
print(response_text)
print()
if status != 200:
raise Exception(f"Request did not return a 200 status code: {status}")
@pytest.mark.asyncio
async def test_routes():
"""
Check if 200
"""
async with aiohttp.ClientSession() as session:
url = "http://0.0.0.0:4000/routes"
async with session.get(url) as response:
status = response.status
response_text = await response.text()
print(response_text)
print()
if status != 200:
raise Exception(f"Request did not return a 200 status code: {status}")