From 55ca438cf1156e3b7e92cfbf92b0dc122b2a0c0b Mon Sep 17 00:00:00 2001 From: filipecosta90 Date: Thu, 16 Nov 2023 18:45:22 +0000 Subject: [PATCH] Included data import test cases --- tests/data-import-2-keys-expiration.txt | 3 + tests/data-import-2-keys.txt | 3 + tests/include.py | 9 +++ tests/run_tests.sh | 4 +- tests/tests_oss_simple_flow.py | 73 +++++++++++++++++++++++-- 5 files changed, 85 insertions(+), 7 deletions(-) create mode 100644 tests/data-import-2-keys-expiration.txt create mode 100644 tests/data-import-2-keys.txt diff --git a/tests/data-import-2-keys-expiration.txt b/tests/data-import-2-keys-expiration.txt new file mode 100644 index 00000000..93e56282 --- /dev/null +++ b/tests/data-import-2-keys-expiration.txt @@ -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 diff --git a/tests/data-import-2-keys.txt b/tests/data-import-2-keys.txt new file mode 100644 index 00000000..092e807c --- /dev/null +++ b/tests/data-import-2-keys.txt @@ -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 diff --git a/tests/include.py b/tests/include.py index dd268883..a010637c 100644 --- a/tests/include.py +++ b/tests/include.py @@ -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): @@ -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) @@ -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) @@ -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) diff --git a/tests/run_tests.sh b/tests/run_tests.sh index 58f12b0d..3e55c10d 100755 --- a/tests/run_tests.sh +++ b/tests/run_tests.sh @@ -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 diff --git a/tests/tests_oss_simple_flow.py b/tests/tests_oss_simple_flow.py index f0743acd..d08ecd4d 100644 --- a/tests/tests_oss_simple_flow.py +++ b/tests/tests_oss_simple_flow.py @@ -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 @@ -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) @@ -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) +