From 4266d9fcd1f0e51700354145b350051b8a3fe60e Mon Sep 17 00:00:00 2001 From: vegetableysm Date: Tue, 27 Feb 2024 16:29:18 +0800 Subject: [PATCH] Add code to runner.py for kv state cache test. Signed-off-by: vegetableysm --- test/kv_state_cache_multi_test.cc | 87 +++++++++++++++++++++++++++++++ test/runner.py | 38 ++++++++++++++ 2 files changed, 125 insertions(+) create mode 100644 test/kv_state_cache_multi_test.cc diff --git a/test/kv_state_cache_multi_test.cc b/test/kv_state_cache_multi_test.cc new file mode 100644 index 000000000..dad9764d9 --- /dev/null +++ b/test/kv_state_cache_multi_test.cc @@ -0,0 +1,87 @@ +/** Copyright 2020-2023 Alibaba Group Holding Limited. + +Licensed under the Apache License, Version 2.0 (the "License"); +you may not use this file except in compliance with the License. +You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, software +distributed under the License is distributed on an "AS IS" BASIS, +WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. +See the License for the specific language governing permissions and +limitations under the License. +*/ + +#include +#include +#include +#include +#include +#include + +#include "common/util/logging.h" + +char process_name[] = "kv_state_cache_test"; +char arg_0[] = "-s"; +char token_sequence_1[] = "1"; +char token_sequence_2[] = "2"; +char token_sequence_3[] = "3"; +char token_sequence_4[] = "4"; + +const char* program = "./build/bin/kv_state_cache_test"; + +pid_t create_subprocess(char* argv[]) { + pid_t pid = fork(); + if (pid == -1) { + std::cerr << "Failed to fork()" << std::endl; + exit(1); + } else if (pid > 0) { + return pid; + } else { + execv(program, argv); + std::cerr << "Failed to exec()" << std::endl; + exit(1); + } +} + +int main(int argc, char** argv) { + std::string sockets[2]; + std::string rpc_endpoint; + for (int i = 1; i < argc; i++) { + if (strcmp(argv[i], "--vineyard-endpoint") == 0) { + rpc_endpoint = std::string(argv[i + 1]); + } else if (strcmp(argv[i], "--vineyard-ipc-sockets") == 0) { + sockets[0] = std::string(argv[i + 1]); + sockets[1] = std::string(argv[i + 2]); + } + } + + char* socket_str[2]; + socket_str[0] = (char*) malloc(sockets[0].length() + 1); + socket_str[1] = (char*) malloc(sockets[1].length() + 1); + memset(socket_str[0], 0, sockets[0].length() + 1); + memset(socket_str[1], 0, sockets[1].length() + 1); + strcpy(socket_str[0], sockets[0].c_str()); + strcpy(socket_str[1], sockets[1].c_str()); + + char* args_1[] = {process_name, socket_str[0], arg_0, + token_sequence_1, token_sequence_2, token_sequence_3, + token_sequence_4, nullptr}; + char* args_2[] = {process_name, socket_str[1], arg_0, + token_sequence_1, token_sequence_2, token_sequence_3, + nullptr}; + + std::vector pids; + pids.push_back(create_subprocess(args_1)); + pids.push_back(create_subprocess(args_2)); + for (size_t i = 0; i < pids.size(); i++) { + int status; + waitpid(pids[i], &status, 0); + if (WIFEXITED(status) && WEXITSTATUS(status) != 0) { + return 1; + } + } + + return 0; +} diff --git a/test/runner.py b/test/runner.py index 5148226b4..7ecead2b0 100755 --- a/test/runner.py +++ b/test/runner.py @@ -680,6 +680,37 @@ def run_scale_in_out_tests(meta, allocator, endpoints, instance_size=4): ) as instances: # pylint: disable=unused-variable time.sleep(5) +def run_cpp_deploy_tests(meta, allocator, endpoints): + meta_prefix = 'vineyard_test_%s' % time.time() + metadata_settings = make_metadata_settings(meta, endpoints, meta_prefix) + + instance_size = 2 + with start_multiple_vineyardd( + metadata_settings, + ['--allocator', allocator], + default_ipc_socket=VINEYARD_CI_IPC_SOCKET, + instance_size=instance_size, + nowait=False, + ) as instances: # noqa: F841, pylint: disable=unused-variable + vineyard_ipc_socket_1 = '%s.%d' % (VINEYARD_CI_IPC_SOCKET, 0) + vineyard_ipc_socket_2 = '%s.%d' % (VINEYARD_CI_IPC_SOCKET, 1) + + rpc_socket_port = instances[0][1] + print(rpc_socket_port) + print(vineyard_ipc_socket_1) + print(vineyard_ipc_socket_2) + print("===========") + subprocess.check_call( + [ + './build/bin/kv_state_cache_multi_test', + '--vineyard-endpoint', + 'localhost:%s' % rpc_socket_port, + '--vineyard-ipc-sockets', + vineyard_ipc_socket_1, + vineyard_ipc_socket_2, + ], + cwd=os.path.join(os.path.dirname(os.path.abspath(__file__)), '..'), + ) def run_python_deploy_tests(meta, allocator, endpoints, test_args, with_migration): meta_prefix = 'vineyard_test_%s' % time.time() @@ -941,6 +972,13 @@ def execute_tests(args): ) if args.with_deployment: + with start_metadata_engine(args.meta) as (_, endpoints): + run_cpp_deploy_tests( + args.meta, + args.allocator, + endpoints, + ) + with start_metadata_engine(args.meta) as (_, endpoints): run_scale_in_out_tests( args.meta, args.allocator, endpoints, instance_size=4