Skip to content

Commit

Permalink
Included data import test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
filipecosta90 committed Nov 16, 2023
1 parent efbeda8 commit 55ca438
Show file tree
Hide file tree
Showing 5 changed files with 85 additions and 7 deletions.
3 changes: 3 additions & 0 deletions tests/data-import-2-keys-expiration.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dumpflags, time, exptime, nbytes, nsuffix, it_flags, clsid, nkey, key, data
0, 0, 10, 12, 0, 0, 0, 4, key1, xxxxxxxxxx
0, 0, 10, 14, 0, 0, 0, 4, key2, aaaaaaaaaaaa
3 changes: 3 additions & 0 deletions tests/data-import-2-keys.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
dumpflags, time, exptime, nbytes, nsuffix, it_flags, clsid, nkey, key, data
0, 0, 0, 12, 0, 0, 0, 4, key1, xxxxxxxxxx
0, 0, 0, 14, 0, 0, 0, 4, key2, aaaaaaaaaaaa
9 changes: 9 additions & 0 deletions tests/include.py
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
import glob
import os
import logging

MEMTIER_BINARY = os.environ.get("MEMTIER_BINARY", "memtier_benchmark")
TLS_CERT = os.environ.get("TLS_CERT", "")
ROOT_FOLDER = os.environ.get("ROOT_FOLDER", "")
TLS_KEY = os.environ.get("TLS_KEY", "")
TLS_CACERT = os.environ.get("TLS_CACERT", "")
TLS_PROTOCOLS = os.environ.get("TLS_PROTOCOLS", "")
VERBOSE = bool(int(os.environ.get("VERBOSE","0")))


def ensure_tls_protocols(master_nodes_connections):
Expand All @@ -27,6 +30,7 @@ def assert_minimum_memtier_outcomes(config, env, memtier_ok, overall_expected_re
env.assertTrue(os.path.isfile('{0}/mb.json'.format(config.results_dir)))
if overall_request_delta is None:
# assert we have the expected request count
logging.debug(f"Checking if expected value {overall_expected_request_count} matches the actual value {overall_request_count}")
env.assertEqual(overall_expected_request_count, overall_request_count)
else:
env.assertAlmostEqual(overall_expected_request_count, overall_request_count,overall_request_delta)
Expand All @@ -35,6 +39,10 @@ def assert_minimum_memtier_outcomes(config, env, memtier_ok, overall_expected_re
debugPrintMemtierOnError(config, env)

def add_required_env_arguments(benchmark_specs, config, env, master_nodes_list):
if VERBOSE:
import logging
logging.basicConfig(level=logging.DEBUG)

# if we've specified TLS_PROTOCOLS ensure we configure it on redis
master_nodes_connections = env.getOSSMasterNodesConnectionList()
ensure_tls_protocols(master_nodes_connections)
Expand Down Expand Up @@ -137,6 +145,7 @@ def assert_keyspace_range(env, key_max, key_min, master_nodes_connections):
expected_keyspace_range = key_max - key_min + 1
overall_keyspace_range = agg_keyspace_range(master_nodes_connections)
# assert we have the expected keyspace range
logging.debug(f"Checking if expected keyspace value {expected_keyspace_range} matches the actual value {overall_keyspace_range}")
env.assertEqual(expected_keyspace_range, overall_keyspace_range)


Expand Down
4 changes: 2 additions & 2 deletions tests/run_tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -79,12 +79,12 @@ cd $ROOT/tests

E=0
[[ $OSS_STANDALONE == 1 ]] && {
(TLS_KEY=$TLS_KEY TLS_CERT=$TLS_CERT TLS_CACERT=$TLS_CACERT MEMTIER_BINARY=$MEMTIER_BINARY RLTEST_ARGS="${RLTEST_ARGS}" run_tests "tests on OSS standalone")
(ROOT_FOLDER=$ROOT TLS_KEY=$TLS_KEY TLS_CERT=$TLS_CERT TLS_CACERT=$TLS_CACERT MEMTIER_BINARY=$MEMTIER_BINARY RLTEST_ARGS="${RLTEST_ARGS}" run_tests "tests on OSS standalone")
((E |= $?))
} || true

[[ $OSS_CLUSTER == 1 ]] && {
(TLS_KEY=$TLS_KEY TLS_CERT=$TLS_CERT TLS_CACERT=$TLS_CACERT MEMTIER_BINARY=$MEMTIER_BINARY RLTEST_ARGS="${RLTEST_ARGS} --env oss-cluster --shards-count $SHARDS" run_tests "tests on OSS cluster")
(ROOT_FOLDER=$ROOT TLS_KEY=$TLS_KEY TLS_CERT=$TLS_CERT TLS_CACERT=$TLS_CACERT MEMTIER_BINARY=$MEMTIER_BINARY RLTEST_ARGS="${RLTEST_ARGS} --env oss-cluster --shards-count $SHARDS" run_tests "tests on OSS cluster")
((E |= $?))
} || true

Expand Down
73 changes: 68 additions & 5 deletions tests/tests_oss_simple_flow.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,8 @@
from mbdirector.benchmark import Benchmark
from mbdirector.runner import RunConfig


import logging

def test_preload_and_set_get(env):
key_max = 500000
key_min = 1
Expand Down Expand Up @@ -355,16 +356,16 @@ def test_default_arbitrary_command_hset(env):
def test_default_arbitrary_command_hset_multi_data_placeholders(env):
benchmark_specs = {"name": env.testName, "args": ['--command=HSET __key__ field1 __data__ field2 __data__ field3 __data__']}
addTLSArgs(benchmark_specs, env)
config = get_default_memtier_config()
memtier_config = get_default_memtier_config()
master_nodes_list = env.getMasterNodesList()
overall_expected_request_count = get_expected_request_count(config)
overall_expected_request_count = get_expected_request_count(memtier_config)

add_required_env_arguments(benchmark_specs, config, env, master_nodes_list)
add_required_env_arguments(benchmark_specs, memtier_config, env, master_nodes_list)

# Create a temporary directory
test_dir = tempfile.mkdtemp()

config = RunConfig(test_dir, env.testName, config, {})
config = RunConfig(test_dir, env.testName, memtier_config, {})
ensure_clean_benchmark_folder(config.results_dir)

benchmark = Benchmark.from_json(config, benchmark_specs)
Expand Down Expand Up @@ -417,3 +418,65 @@ def test_default_set_get_rate_limited(env):
merged_command_stats = {'cmdstat_set': {'calls': 0}, 'cmdstat_get': {'calls': 0}}
overall_request_count = agg_info_commandstats(master_nodes_connections, merged_command_stats)
assert_minimum_memtier_outcomes(config, env, memtier_ok, overall_expected_request_count, overall_request_count, request_delta)

def test_data_import(env):
benchmark_specs = {"name": env.testName, "args": [f"--data-import={ROOT_FOLDER}/tests/data-import-2-keys.txt",'--ratio=1:1']}
addTLSArgs(benchmark_specs, env)
config = get_default_memtier_config()
master_nodes_list = env.getMasterNodesList()
overall_expected_request_count = get_expected_request_count(config,1, 2)
add_required_env_arguments(benchmark_specs, config, env, master_nodes_list)

# Create a temporary directory
test_dir = tempfile.mkdtemp()

config = RunConfig(test_dir, env.testName, config, {})
ensure_clean_benchmark_folder(config.results_dir)

benchmark = Benchmark.from_json(config, benchmark_specs)

master_nodes_connections = env.getOSSMasterNodesConnectionList()
# reset the commandstats
for master_connection in master_nodes_connections:
master_connection.execute_command("CONFIG", "RESETSTAT")

# benchmark.run() returns True if the return code of memtier_benchmark was 0
memtier_ok = benchmark.run()

assert_keyspace_range(env, 2, 1, master_nodes_connections)

merged_command_stats = {'cmdstat_set': {'calls': 0}, 'cmdstat_get': {'calls': 0}}
overall_request_count = agg_info_commandstats(master_nodes_connections, merged_command_stats)
assert_minimum_memtier_outcomes(config, env, memtier_ok, overall_expected_request_count, overall_request_count)


def test_data_import_setex(env):
benchmark_specs = {"name": env.testName, "args": [f"--data-import={ROOT_FOLDER}/tests/data-import-2-keys-expiration.txt",'--ratio=1:1']}
addTLSArgs(benchmark_specs, env)
config = get_default_memtier_config()
master_nodes_list = env.getMasterNodesList()
overall_expected_request_count = get_expected_request_count(config,1, 2)
add_required_env_arguments(benchmark_specs, config, env, master_nodes_list)

# Create a temporary directory
test_dir = tempfile.mkdtemp()

config = RunConfig(test_dir, env.testName, config, {})
ensure_clean_benchmark_folder(config.results_dir)

benchmark = Benchmark.from_json(config, benchmark_specs)

master_nodes_connections = env.getOSSMasterNodesConnectionList()
# reset the commandstats
for master_connection in master_nodes_connections:
master_connection.execute_command("CONFIG", "RESETSTAT")

# benchmark.run() returns True if the return code of memtier_benchmark was 0
memtier_ok = benchmark.run()

assert_keyspace_range(env, 2, 1, master_nodes_connections)

merged_command_stats = {'cmdstat_setex': {'calls': 0}, 'cmdstat_get': {'calls': 0}}
overall_request_count = agg_info_commandstats(master_nodes_connections, merged_command_stats)
assert_minimum_memtier_outcomes(config, env, memtier_ok, overall_expected_request_count, overall_request_count)

0 comments on commit 55ca438

Please sign in to comment.