-
Notifications
You must be signed in to change notification settings - Fork 878
/
Copy pathtest_benchmark.py
58 lines (43 loc) · 1.33 KB
/
test_benchmark.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
import os
import subprocess
import sys
from pathlib import Path
import pytest
CURR_FILE_PATH = Path(__file__).parent
REPO_ROOT_DIR = CURR_FILE_PATH.parents[1]
def dependencies_available():
try:
import click # noqa
import locust # noqa
import locust_plugins # noqa
except:
return False
return os.system("ab -V") == 0 and os.system("locust -V") == 0
@pytest.mark.skipif(
not dependencies_available(), reason="Dependency not found: ab tool"
)
@pytest.mark.parametrize(
"backend",
(
"ab",
"locust",
),
)
def test_benchmark_e2e(backend):
report_file = Path("/tmp/benchmark/ab_report.csv")
if report_file.exists():
report_file.unlink()
sys.path.append((REPO_ROOT_DIR / "benchmarks").as_posix())
os.chdir(REPO_ROOT_DIR / "benchmarks")
cmd = subprocess.Popen(
f"{sys.executable} ./benchmark-ab.py --concurrency 1 --requests 10 -bb {backend} --generate_graphs True",
shell=True,
stdout=subprocess.PIPE,
)
output_lines = list(cmd.stdout)
assert output_lines[-1].decode("utf-8") == "Test suite execution complete.\n"
assert len(output_lines) == 71
report = report_file.read_text()
assert report.count(",") == 58
report.split(",")[7] == "Requests"
report.split("\n")[1].split(",")[7] == "10"