-
-
Notifications
You must be signed in to change notification settings - Fork 8
Expand file tree
/
Copy pathtest_benchmarks.py
More file actions
129 lines (108 loc) · 3.7 KB
/
Copy pathtest_benchmarks.py
File metadata and controls
129 lines (108 loc) · 3.7 KB
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
117
118
119
120
121
122
123
124
125
126
127
128
129
"""Tests for the benchmarks API endpoints."""
async def test_all_benchmark_names_empty(client):
response = await client.get("/api/benchmarks")
assert response.status_code == 200
assert response.json() == []
async def test_all_benchmark_names(client, sample_benchmark_result):
response = await client.get("/api/benchmarks")
assert response.status_code == 200
data = response.json()
assert "json_dumps" in data
async def test_filtered_benchmark_names(client, sample_benchmark_result):
response = await client.get(
"/api/benchmark-names",
params={
"environment_id": "linux-x86_64",
"binary_id": "default",
"python_major": 3,
"python_minor": 14,
},
)
assert response.status_code == 200
data = response.json()
assert "json_dumps" in data
async def test_filtered_benchmark_names_no_match(client, sample_benchmark_result):
response = await client.get(
"/api/benchmark-names",
params={
"environment_id": "linux-x86_64",
"binary_id": "default",
"python_major": 3,
"python_minor": 99,
},
)
assert response.status_code == 200
assert response.json() == []
async def test_diff_table(client, sample_benchmark_result):
response = await client.get(
"/api/diff",
params={
"commit_sha": "a" * 40,
"binary_id": "default",
"environment_id": "linux-x86_64",
},
)
assert response.status_code == 200
data = response.json()
assert len(data) == 1
row = data[0]
assert row["benchmark_name"] == "json_dumps"
assert row["curr_metric_value"] == 1_000_000
assert row["metric_key"] == "high_watermark_bytes"
assert row["has_flamegraph"] is True
async def test_diff_table_commit_not_found(client):
response = await client.get(
"/api/diff",
params={
"commit_sha": "f" * 40,
"binary_id": "default",
"environment_id": "linux-x86_64",
},
)
assert response.status_code == 404
async def test_trends(client, sample_benchmark_result):
response = await client.get(
"/api/trends",
params={
"benchmark_name": "json_dumps",
"binary_id": "default",
"environment_id": "linux-x86_64",
"python_major": 3,
"python_minor": 14,
},
)
assert response.status_code == 200
data = response.json()
assert len(data) == 1
assert data[0]["sha"] == "a" * 40
assert data[0]["high_watermark_bytes"] == 1_000_000
async def test_trends_batch(client, sample_benchmark_result):
response = await client.post(
"/api/trends-batch",
json={
"trend_queries": [
{
"benchmark_name": "json_dumps",
"binary_id": "default",
"environment_id": "linux-x86_64",
"python_major": 3,
"python_minor": 14,
"limit": 50,
}
]
},
)
assert response.status_code == 200
data = response.json()
assert "results" in data
assert len(data["results"]) == 1
async def test_flamegraph(client, sample_benchmark_result):
result_id = sample_benchmark_result.id
response = await client.get(f"/api/flamegraph/{result_id}")
assert response.status_code == 200
data = response.json()
assert data["flamegraph_html"] == "<html>flamegraph</html>"
assert data["benchmark_name"] == "json_dumps"
async def test_flamegraph_not_found(client):
response = await client.get("/api/flamegraph/nonexistent")
assert response.status_code == 404