11import argparse
22import os
33import time
4+ import sys
45from pathlib import Path
56
7+ repo_path = Path (__file__ ).resolve ().parent .parent .parent
8+ repo_path_normalized = str (repo_path )
9+ sys .path .append (str (repo_path / "ci" ))
10+
611from ci .defs .defs import ToolSet , chcache_secret
712from ci .jobs .scripts .clickhouse_proc import ClickHouseProc
813from ci .jobs .scripts .functional_tests_results import FTResultsProcessor
1419current_directory = Utils .cwd ()
1520build_dir = f"{ current_directory } /ci/tmp/fast_build"
1621temp_dir = f"{ current_directory } /ci/tmp/"
17- repo_path_normalized = "/ClickHouse"
18- build_dir_normalized = f"{ repo_path_normalized } /ci/tmp/fast_build"
22+ build_dir_normalized = str (repo_path / "ci" / "tmp" / "fast_build" )
1923
2024
2125def clone_submodules ():
@@ -69,8 +73,8 @@ def clone_submodules():
6973 # Roll back to 10 if this starts hitting GitHub rate limits.
7074 command = f"xargs --max-procs={ min ([Utils .cpu_count (), 20 ])} --null --no-run-if-empty --max-args=1 git submodule update --depth 1 --single-branch" ,
7175 stdin_str = "\0 " .join (submodules_to_update ) + "\0 " ,
72- timeout = 240 ,
73- retries = 2 ,
76+ timeout = 300 ,
77+ retries = 3 ,
7478 verbose = True ,
7579 )
7680 # NOTE: the three "git submodule foreach" cleanup commands (reset --hard,
@@ -118,9 +122,9 @@ def parse_args():
118122 parser = argparse .ArgumentParser (description = "ClickHouse Fast Test Job" )
119123 parser .add_argument ("--test" , help = "Optional test_case name to run" , default = "" )
120124 parser .add_argument ("--param" , help = "Optional custom job start stage" , default = None )
125+ parser .add_argument ("--set-status-success" , help = "Forcefully set a green status" , action = "store_true" )
121126 return parser .parse_args ()
122127
123-
124128def main ():
125129 args = parse_args ()
126130 stop_watch = Utils .Stopwatch ()
@@ -136,6 +140,28 @@ def main():
136140
137141 clickhouse_bin_path = Path (f"{ build_dir } /programs/clickhouse" )
138142
143+ for path in [
144+ Path (temp_dir ) / "clickhouse" ,
145+ clickhouse_bin_path ,
146+ Path (current_directory ) / "clickhouse" ,
147+ ]:
148+ if path .is_file ():
149+ clickhouse_bin_path = path
150+ print (f"NOTE: clickhouse binary is found [{ clickhouse_bin_path } ] - skip the build" )
151+
152+ stages = [JobStages .CONFIG , JobStages .TEST ]
153+ resolved_clickhouse_bin_path = clickhouse_bin_path .resolve ()
154+ Utils .link (resolved_clickhouse_bin_path , resolved_clickhouse_bin_path .parent / "clickhouse-server" )
155+ Utils .link (resolved_clickhouse_bin_path , resolved_clickhouse_bin_path .parent / "clickhouse-client" )
156+ Utils .link (resolved_clickhouse_bin_path , resolved_clickhouse_bin_path .parent / "clickhouse-local" )
157+ Shell .check (f"chmod +x { resolved_clickhouse_bin_path } " , strict = True )
158+
159+ break
160+ else :
161+ print (
162+ f"NOTE: clickhouse binary is not found [{ clickhouse_bin_path } ] - will be built"
163+ )
164+
139165 # Global sccache settings for local and CI runs
140166 os .environ ["SCCACHE_DIR" ] = f"{ temp_dir } /sccache"
141167 os .environ ["SCCACHE_CACHE_SIZE" ] = "40G"
@@ -145,36 +171,10 @@ def main():
145171 os .environ ["SCCACHE_ERROR_LOG" ] = f"{ build_dir } /sccache.log"
146172 os .environ ["SCCACHE_LOG" ] = "info"
147173
148- if Info ().is_local_run :
174+ info = Info ()
175+ if info .is_local_run :
176+ print ("NOTE: It's a local run" )
149177 os .environ ["SCCACHE_S3_NO_CREDENTIALS" ] = "true"
150- for path in [
151- clickhouse_bin_path ,
152- Path (temp_dir ) / "clickhouse" ,
153- Path (current_directory ) / "clickhouse" ,
154- ]:
155- if path .exists ():
156- clickhouse_bin_path = path
157- break
158- if clickhouse_bin_path .exists ():
159- print (
160- f"NOTE: It's a local run and clickhouse binary is found [{ clickhouse_bin_path } ] - skip the build"
161- )
162- stages = [JobStages .CONFIG , JobStages .TEST ]
163- resolved_clickhouse_bin_path = clickhouse_bin_path .resolve ()
164- Shell .check (
165- f"ln -sf { resolved_clickhouse_bin_path } { resolved_clickhouse_bin_path .parent } /clickhouse-server" ,
166- strict = True ,
167- )
168- Shell .check (
169- f"ln -sf { resolved_clickhouse_bin_path } { resolved_clickhouse_bin_path .parent } /clickhouse-client" ,
170- strict = True ,
171- )
172- Shell .check (f"chmod +x { resolved_clickhouse_bin_path } " , strict = True )
173- else :
174- print (
175- f"NOTE: It's a local run and clickhouse binary is not found [{ clickhouse_bin_path } ] - will be built"
176- )
177- time .sleep (5 )
178178 else :
179179 os .environ ["CH_HOSTNAME" ] = (
180180 "https://build-cache.eu-west-1.aws.clickhouse-staging.com"
@@ -258,8 +258,9 @@ def main():
258258
259259 if res and JobStages .CONFIG in stages :
260260 commands = [
261+ f"mkdir -p { temp_dir } /etc/clickhouse-server" ,
261262 f"cp ./programs/server/config.xml ./programs/server/users.xml { temp_dir } /etc/clickhouse-server/" ,
262- f"./tests/config/install.sh /etc/clickhouse-server /etc/clickhouse-client --fast-test" ,
263+ f"./tests/config/install.sh { temp_dir } /etc/clickhouse-server { temp_dir } /etc/clickhouse-client --fast-test" ,
263264 # f"cp -a {current_directory}/programs/server/config.d/log_to_console.xml {temp_dir}/etc/clickhouse-server/config.d/",
264265 f"rm -f { temp_dir } /etc/clickhouse-server/config.d/secure_ports.xml" ,
265266 update_path_ch_config ,
@@ -272,7 +273,12 @@ def main():
272273 )
273274 res = results [- 1 ].is_ok ()
274275
275- CH = ClickHouseProc (fast_test = True )
276+ CH = ClickHouseProc (
277+ ch_config_dir = f"{ temp_dir } /etc/clickhouse-server" ,
278+ ch_var_lib_dir = f"{ temp_dir } /var/lib/clickhouse" ,
279+ )
280+ CH .install_configs ()
281+
276282 attach_debug = False
277283 if res and JobStages .TEST in stages :
278284 stop_watch_ = Utils .Stopwatch ()
@@ -290,34 +296,45 @@ def main():
290296 stop_watch_ = Utils .Stopwatch ()
291297 step_name = "Tests"
292298 print (step_name )
293- res = res and CH .run_fast_test (test = args .test or "" )
294- if res :
295- results .append (FTResultsProcessor (wd = Settings .OUTPUT_DIR ).run ())
296- results [- 1 ].set_timing (stopwatch = stop_watch_ )
297- else :
298- results .append (
299+
300+ # Fast test runs lightweight SQL tests that are not CPU-bound,
301+ # so we can use more parallelism than the default cpu_count/2.
302+ nproc_fast = max (1 , int (Utils .cpu_count () * 3 / 4 ))
303+
304+ fast_test_command = f"cd { temp_dir } && clickhouse-test --hung-check --trace --capture-client-stacktrace --no-random-settings --no-random-merge-tree-settings --no-long --testname --shard --check-zookeeper-session --order random --report-logs-stats --fast-tests-only --no-stateful --jobs { nproc_fast } "
305+ if args .test :
306+ fast_test_command += f" -- '{ args .test } '"
307+
308+ res = CH .run_test (fast_test_command )
309+
310+ test_results = FTResultsProcessor (wd = Settings .OUTPUT_DIR ).run ()
311+ if not res :
312+ test_results .results .append (
299313 Result .create_from (
300- name = step_name ,
301- status = Result .Status .ERROR ,
302- stopwatch = stop_watch_ ,
303- info = "Tests run error" ,
314+ name = "clickhouse-test" ,
315+ status = Result .StatusExtended .FAIL ,
316+ info = "clickhouse-test error" ,
304317 )
305318 )
319+ attach_debug = True
320+
321+ results .append (test_results )
322+ results [- 1 ].set_timing (stopwatch = stop_watch_ )
306323 if not results [- 1 ].is_ok ():
307324 attach_debug = True
308325 job_info = results [- 1 ].info
309326
310327 if attach_debug :
311328 attach_files += [
312329 clickhouse_bin_path ,
313- f"{ temp_dir } /var/log/clickhouse-server/clickhouse-server.err.log" ,
314- f"{ temp_dir } /var/log/clickhouse-server/clickhouse-server.log" ,
330+ * CH .prepare_logs (info = info , all = True ),
315331 ]
316332
317- CH .terminate ()
333+ CH .terminate (force = True )
318334
335+ status = Result .Status .SUCCESS if args .set_status_success else ""
319336 Result .create_from (
320- results = results , stopwatch = stop_watch , files = attach_files , info = job_info
337+ results = results , status = status , stopwatch = stop_watch , files = attach_files , info = job_info
321338 ).complete_job ()
322339
323340
0 commit comments