Skip to content

Commit ac7eba2

Browse files
Increased coverage of tool. General code improvement (#69)
1 parent 08cab1e commit ac7eba2

8 files changed

+111
-5
lines changed

redisbench_admin/run_local/run_local.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@
2424
extract_git_vars,
2525
validateResultExpectations,
2626
)
27-
from redisbench_admin.utils.utils import decompress_file
27+
from redisbench_admin.utils.utils import decompress_file, get_decompressed_filename
2828

2929

3030
def run_local_command_logic(args):
@@ -214,7 +214,10 @@ def checkBenchmarkBinariesLocalRequirements(benchmark_config, allowed_tools, bin
214214
logging.info(
215215
"Decompressing {} into {}.".format(
216216
full_path, binaries_localtemp_dir))
217-
full_path = decompress_file(full_path,binaries_localtemp_dir)
217+
if not os.path.exists(get_decompressed_filename(full_path)):
218+
full_path = decompress_file(full_path,binaries_localtemp_dir)
219+
else:
220+
full_path = get_decompressed_filename(full_path)
218221
benchmark_tool_workdir = os.path.abspath(full_path)
219222
executable = stat.S_IEXEC | stat.S_IXGRP | stat.S_IXOTH
220223
which_benchmark_tool = whichLocal(benchmark_tool, executable, full_path, which_benchmark_tool)

redisbench_admin/utils/utils.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,14 @@ def required_utilities(utility_list):
5151
return result
5252

5353

54+
def get_decompressed_filename(compressed_filename:str):
55+
uncompressed_filename = None
56+
for suffix in [".zip",".tar.gz","tar"]:
57+
if compressed_filename.endswith(suffix):
58+
uncompressed_filename = compressed_filename[:-len(suffix)]
59+
return uncompressed_filename
60+
61+
5462
def decompress_file(compressed_filename:str, path=None):
5563
uncompressed_filename = compressed_filename
5664
logging.warning(

tests/test_common.py

Lines changed: 29 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,8 @@
88
split_tags_string,
99
get_or_None,
1010
)
11-
from redisbench_admin.run.common import get_start_time_vars, prepare_benchmark_parameters
11+
from redisbench_admin.run.common import get_start_time_vars, prepare_benchmark_parameters, \
12+
extract_benchmark_tool_settings, common_exporter_logic, process_default_yaml_properties_file
1213

1314

1415
class Test(TestCase):
@@ -54,8 +55,34 @@ def test_get_start_time_vars():
5455
def test_prepare_benchmark_parameters():
5556
with open("./tests/test_data/ycsb-config.yml", "r") as yml_file:
5657
benchmark_config = yaml.safe_load(yml_file)
57-
command_arr, command_str = prepare_benchmark_parameters(benchmark_config, "ycsb", "6380", "localhost",
58+
command_arr, command_str = prepare_benchmark_parameters(benchmark_config, "ycsb", "6380", "localhost",
5859
"out.txt", False)
5960
assert command_str == "ycsb load redisearch -P workloads/workload-ecommerce -p \"threadcount=64\"" \
6061
" -p \"redis.host=localhost\" -p \"redis.port=6380\"" \
6162
" -p \"recordcount=100000\" -p \"operationcount=100000\""
63+
64+
65+
def test_extract_benchmark_tool_settings():
66+
config_files = ["./tests/test_data/ycsb-config.yml", "./tests/test_data/redis-benchmark.yml",
67+
"./tests/test_data/redisgraph-benchmark-go.yml"]
68+
for file in config_files:
69+
with open(file, "r") as yml_file:
70+
benchmark_config = yaml.safe_load(yml_file)
71+
benchmark_min_tool_version, benchmark_min_tool_version_major, benchmark_min_tool_version_minor, benchmark_min_tool_version_patch, benchmark_tool, benchmark_tool_source = extract_benchmark_tool_settings(
72+
benchmark_config)
73+
assert benchmark_tool is not None
74+
prepare_benchmark_parameters(benchmark_config, benchmark_tool, "9999", "localhost", "out.txt", False)
75+
76+
77+
def test_common_exporter_logic():
78+
# negative test
79+
common_exporter_logic(None, None, None, None, None, None,
80+
None, None, None, None)
81+
82+
83+
def test_process_default_yaml_properties_file():
84+
with open("./tests/test_data/common-properties-v0.1.yml", "r") as yml_file:
85+
default_kpis, default_metrics, exporter_timemetric_path = process_default_yaml_properties_file({},{},"1.yml",None,yml_file)
86+
assert exporter_timemetric_path == "$.StartTime"
87+
assert default_kpis is None
88+
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
version: 0.1
2+
exporter:
3+
redistimeseries:
4+
timemetric: "$.StartTime"
5+
metrics:
6+
- "$.Tests.Overall.rps"
7+
- "$.Tests.Overall.avg_latency_ms"
8+
- "$.Tests.Overall.p50_latency_ms"
9+
- "$.Tests.Overall.p95_latency_ms"
10+
- "$.Tests.Overall.p99_latency_ms"
11+
- "$.Tests.Overall.max_latency_ms"
12+
- "$.Tests.Overall.min_latency_ms"
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"test","rps","avg_latency_ms","min_latency_ms","p50_latency_ms","p95_latency_ms","p99_latency_ms","max_latency_ms"
2+
"SET","139082.06","0.188","0.040","0.167","0.295","0.735","2.215"
3+
"GET","136986.30","0.187","0.048","0.183","0.247","0.391","0.887"

tests/test_data/redis-benchmark.yml

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
name: "tsbs-scale100-single-groupby-1-8-1"
2+
remote:
3+
- type: oss-standalone
4+
- setup: redistimeseries-m5
5+
dbconfig:
6+
- dataset: "https://s3.amazonaws.com/benchmarks.redislabs/redistimeseries/tsbs/datasets/devops/functional/scale-100-redistimeseries_data.rdb"
7+
clientconfig:
8+
- tool: redis-benchmark
9+
- min-tool-version: "6.2.0"
10+
- parameters:
11+
- clients: 50
12+
- requests: 100000
13+
- threads: 1
14+
- pipeline: 1
15+
- command: '"TS.MRANGE" "1609613705646" "1609617305646" "WITHLABELS" "AGGREGATION" "MAX" "60000" "FILTER" "measurement=cpu" "fieldname=usage_user" "hostname=(host_49,host_3,host_35,host_39,host_75,host_15,host_21,host_11)" "GROUPBY" "hostname" "REDUCE" "max"'

tests/test_redis_benchmark.py

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
import shutil
2+
3+
import yaml
4+
5+
from redisbench_admin.run.redis_benchmark.redis_benchmark import prepareRedisBenchmarkCommand, \
6+
redis_benchmark_ensure_min_version_local, redis_benchmark_from_stdout_csv_to_json
7+
8+
9+
def test_prepare_redis_benchmark_command():
10+
with open("./tests/test_data/redisgraph-benchmark-go.yml", "r") as yml_file:
11+
benchmark_config = yaml.safe_load(yml_file)
12+
for k in benchmark_config["clientconfig"]:
13+
if 'parameters' in k:
14+
command_arr, command_str = prepareRedisBenchmarkCommand("redis-benchmark", "localhost",
15+
"6380", k)
16+
assert command_str == "redis-benchmark -h localhost -p 6380 --csv -e -c 32 --threads 4 -n 1000000"
17+
18+
19+
def test_redis_benchmark_ensure_min_version_local():
20+
redis_benchmark_bin = shutil.which("redis-benchmark")
21+
if redis_benchmark_bin:
22+
redis_benchmark_ensure_min_version_local(redis_benchmark_bin, "6.2.0", "6", "2", "0")
23+
24+
25+
def test_redis_benchmark_from_stdout_csv_to_json():
26+
with open("./tests/test_data/redis-benchmark-6.2.0-csv.out", "r") as csv_file:
27+
csv_data = csv_file.read()
28+
results_dict = redis_benchmark_from_stdout_csv_to_json(csv_data, 1, "1")
29+
assert "SET" in results_dict["Tests"]
30+
assert "GET" in results_dict["Tests"]

tests/test_redis_benchmark_csv_format.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
from unittest import TestCase
22

33
from redisbench_admin.export.redis_benchmark.redis_benchmark_csv_format import (
4-
fill_tags_from_passed_array,
4+
fill_tags_from_passed_array, redis_benchmark_export_logic,
55
)
6+
from redisbench_admin.run.redis_benchmark.redis_benchmark import redis_benchmark_from_stdout_csv_to_json
67

78

89
class Test(TestCase):
@@ -19,3 +20,10 @@ def test_fill_tags_from_passed_array(self):
1920
) = fill_tags_from_passed_array(kv_array)
2021
assert git_sha == "a331"
2122
assert deployment_type == None
23+
24+
25+
def test_redis_benchmark_export_logic():
26+
with open("./tests/test_data/redis-benchmark-6.2.0-csv.out", "r") as csv_file:
27+
csv_data = csv_file.read()
28+
results_dict = redis_benchmark_from_stdout_csv_to_json(csv_data, 1, "1")
29+
redis_benchmark_export_logic(results_dict,[],None,{},False)

0 commit comments

Comments
 (0)