Skip to content

Commit

Permalink
Add code to runner.py for kv state cache test.
Browse files Browse the repository at this point in the history
Signed-off-by: vegetableysm <[email protected]>
  • Loading branch information
vegetableysm committed Feb 27, 2024
1 parent 6efb819 commit 4266d9f
Show file tree
Hide file tree
Showing 2 changed files with 125 additions and 0 deletions.
87 changes: 87 additions & 0 deletions test/kv_state_cache_multi_test.cc
Original file line number Diff line number Diff line change
@@ -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 <sys/wait.h>
#include <unistd.h>
#include <cstring>
#include <iostream>
#include <random>
#include <vector>

#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<pid_t> 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;
}
38 changes: 38 additions & 0 deletions test/runner.py
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 4266d9f

Please sign in to comment.