|
| 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 |
0 commit comments