Skip to content

Commit f83bbce

Browse files
authored
Merge pull request #10 from cpppracticum/yandex_tank
yandex tank tests
2 parents 2b1164c + 9f84979 commit f83bbce

3 files changed

Lines changed: 99 additions & 0 deletions

File tree

tests/test_s03_ammo.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
import os
2+
import glob
3+
4+
from pathlib import Path
5+
6+
import pytest
7+
8+
9+
@pytest.fixture
10+
def directory():
11+
return Path(os.environ['DIRECTORY'])
12+
13+
14+
def test_only_200(directory):
15+
logdirname = max(glob.glob(os.path.join(directory, '*/')), key=os.path.getctime)
16+
filename = ''
17+
for file_name in os.listdir(logdirname):
18+
name, end = os.path.splitext(file_name)
19+
if name.startswith('phout_') and end == '.log':
20+
filename = file_name
21+
22+
with open(os.path.join(logdirname, filename)) as phout:
23+
lines = phout.readlines()
24+
print(lines[:10])
25+
for line in lines:
26+
assert line.split()[-1] == '200'

tests/test_s03_load.py

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
import os
2+
import glob
3+
4+
from pathlib import Path
5+
6+
import pytest
7+
8+
import numpy as np
9+
10+
11+
@pytest.fixture
12+
def directory():
13+
return Path(os.environ['DIRECTORY'])
14+
15+
16+
def test_only_200(directory):
17+
logdirname = max(glob.glob(os.path.join(directory, '*/')), key=os.path.getctime)
18+
filename = ''
19+
for file_name in os.listdir(logdirname):
20+
name, end = os.path.splitext(file_name)
21+
if name.startswith('phout_') and end == '.log':
22+
filename = file_name
23+
24+
with open(os.path.join(logdirname, filename)) as phout:
25+
lines = phout.readlines()
26+
print(lines[:10])
27+
for line in lines:
28+
assert line.split()[-1] == '200'
29+
30+
31+
def test_percentiles(directory):
32+
logdirname = max(glob.glob(os.path.join(directory, '*/')), key=os.path.getctime)
33+
filename = ''
34+
for file_name in os.listdir(logdirname):
35+
name, end = os.path.splitext(file_name)
36+
if name.startswith('phout_') and end == '.log':
37+
filename = file_name
38+
39+
with open(os.path.join(logdirname, filename)) as phout:
40+
lines = phout.readlines()
41+
print(lines[:10])
42+
timings = []
43+
for line in lines:
44+
timings.append(float(line.split()[-10]))
45+
arr = np.array(timings)
46+
p50 = np.percentile(arr, 50)
47+
p90 = np.percentile(arr, 90)
48+
assert p50 <= 35000 # 35 ms == 35000 microseconds
49+
assert p90 <= 50000 # 50 ms == 50000 microseconds

tests/test_s03_stress.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
import os, glob
2+
3+
from pathlib import Path
4+
5+
import pytest
6+
7+
8+
@pytest.fixture
9+
def directory():
10+
return Path(os.environ['DIRECTORY'])
11+
12+
13+
def test_mostly_500(directory):
14+
logdirname = max(glob.glob(os.path.join(directory, '*/')), key=os.path.getctime)
15+
filename = ''
16+
for file_name in os.listdir(logdirname):
17+
name, end = os.path.splitext(file_name)
18+
if name.startswith('phout_') and end == '.log':
19+
filename = file_name
20+
21+
with open(os.path.join(logdirname, filename)) as phout:
22+
lines = phout.readlines()
23+
print(lines[:10])
24+
assert len([line for line in lines if line.split()[-1][0] == '5']) >= 0.9 * len(lines)

0 commit comments

Comments
 (0)