2018-10-22 14:31:25 +00:00
|
|
|
#!/usr/bin/env python
|
2020-07-08 08:41:39 +00:00
|
|
|
# -*- coding: utf-8 -*-
|
2018-10-22 14:31:25 +00:00
|
|
|
from multiprocessing import cpu_count
|
|
|
|
from subprocess import Popen, check_call
|
|
|
|
import os
|
|
|
|
import shutil
|
|
|
|
import argparse
|
|
|
|
import logging
|
|
|
|
import time
|
|
|
|
|
2020-07-08 08:41:39 +00:00
|
|
|
|
|
|
|
def get_skip_list_cmd(path):
|
|
|
|
with open(path, 'r') as f:
|
|
|
|
for line in f:
|
|
|
|
if '--use-skip-list' in line:
|
|
|
|
return '--use-skip-list'
|
|
|
|
return ''
|
|
|
|
|
|
|
|
|
2018-10-22 14:31:25 +00:00
|
|
|
def run_perf_test(cmd, xmls_path, output_folder):
|
|
|
|
output_path = os.path.join(output_folder, "perf_stress_run.txt")
|
|
|
|
f = open(output_path, 'w')
|
2019-04-23 10:41:01 +00:00
|
|
|
p = Popen("{} --skip-tags=long --recursive --input-files {}".format(cmd, xmls_path), shell=True, stdout=f, stderr=f)
|
2018-10-22 14:31:25 +00:00
|
|
|
return p
|
|
|
|
|
2020-07-08 08:41:39 +00:00
|
|
|
|
2020-05-13 00:50:21 +00:00
|
|
|
def run_func_test(cmd, output_prefix, num_processes, skip_tests_option):
|
2020-07-08 08:41:39 +00:00
|
|
|
skip_list_opt = get_skip_list_cmd(cmd)
|
2018-10-22 14:31:25 +00:00
|
|
|
output_paths = [os.path.join(output_prefix, "stress_test_run_{}.txt".format(i)) for i in range(num_processes)]
|
|
|
|
f = open(output_paths[0], 'w')
|
2020-07-08 08:41:39 +00:00
|
|
|
main_command = "{} {} {}".format(cmd, skip_list_opt, skip_tests_option)
|
2020-05-14 15:37:37 +00:00
|
|
|
logging.info("Run func tests main cmd '%s'", main_command)
|
|
|
|
pipes = [Popen(main_command, shell=True, stdout=f, stderr=f)]
|
2018-10-22 14:31:25 +00:00
|
|
|
for output_path in output_paths[1:]:
|
|
|
|
time.sleep(0.5)
|
|
|
|
f = open(output_path, 'w')
|
2020-07-08 08:41:39 +00:00
|
|
|
full_command = "{} {} --order=random {}".format(cmd, skip_list_opt, skip_tests_option)
|
2020-05-14 15:37:37 +00:00
|
|
|
logging.info("Run func tests '%s'", full_command)
|
|
|
|
p = Popen(full_command, shell=True, stdout=f, stderr=f)
|
2018-10-22 14:31:25 +00:00
|
|
|
pipes.append(p)
|
|
|
|
return pipes
|
|
|
|
|
2020-07-08 08:41:39 +00:00
|
|
|
|
2018-10-22 14:31:25 +00:00
|
|
|
if __name__ == "__main__":
|
|
|
|
logging.basicConfig(level=logging.INFO, format='%(asctime)s %(message)s')
|
|
|
|
parser = argparse.ArgumentParser(description="ClickHouse script for running stresstest")
|
2020-07-08 08:41:39 +00:00
|
|
|
parser.add_argument("--test-cmd", default='/usr/bin/clickhouse-test')
|
2020-05-13 00:50:21 +00:00
|
|
|
parser.add_argument("--skip-func-tests", default='')
|
2018-10-22 14:31:25 +00:00
|
|
|
parser.add_argument("--client-cmd", default='clickhouse-client')
|
|
|
|
parser.add_argument("--perf-test-cmd", default='clickhouse-performance-test')
|
|
|
|
parser.add_argument("--perf-test-xml-path", default='/usr/share/clickhouse-test/performance/')
|
|
|
|
parser.add_argument("--server-log-folder", default='/var/log/clickhouse-server')
|
|
|
|
parser.add_argument("--output-folder")
|
2018-10-22 17:04:43 +00:00
|
|
|
parser.add_argument("--num-parallel", default=cpu_count() // 3);
|
2018-10-22 14:31:25 +00:00
|
|
|
|
|
|
|
args = parser.parse_args()
|
|
|
|
func_pipes = []
|
|
|
|
perf_process = None
|
2020-07-14 14:47:23 +00:00
|
|
|
perf_process = run_perf_test(args.perf_test_cmd, args.perf_test_xml_path, args.output_folder)
|
|
|
|
func_pipes = run_func_test(args.test_cmd, args.output_folder, args.num_parallel, args.skip_func_tests)
|
2018-10-22 14:31:25 +00:00
|
|
|
|
2020-07-14 14:47:23 +00:00
|
|
|
logging.info("Will wait functests to finish")
|
|
|
|
while True:
|
|
|
|
retcodes = []
|
|
|
|
for p in func_pipes:
|
|
|
|
if p.poll() is not None:
|
|
|
|
retcodes.append(p.returncode)
|
|
|
|
if len(retcodes) == len(func_pipes):
|
|
|
|
break
|
|
|
|
logging.info("Finished %s from %s processes", len(retcodes), len(func_pipes))
|
|
|
|
time.sleep(5)
|
2018-10-22 14:31:25 +00:00
|
|
|
|
2020-07-14 14:47:23 +00:00
|
|
|
logging.info("Stress test finished")
|