From 039cf36acbde218bdccecb661838944474a2705c Mon Sep 17 00:00:00 2001 From: Alexander Kuzmenkov Date: Thu, 16 Jul 2020 21:04:16 +0300 Subject: [PATCH] Minor fixes for query fuzzer --- docker/test/fuzzer/run-fuzzer.sh | 66 ++++++++++++++++++++++++++---- programs/client/Client.cpp | 16 +++++--- src/Functions/FunctionsLogical.cpp | 2 +- 3 files changed, 70 insertions(+), 14 deletions(-) diff --git a/docker/test/fuzzer/run-fuzzer.sh b/docker/test/fuzzer/run-fuzzer.sh index bd0dd1353e..c4a7eb3188 100755 --- a/docker/test/fuzzer/run-fuzzer.sh +++ b/docker/test/fuzzer/run-fuzzer.sh @@ -37,6 +37,8 @@ function download wget -nv -nd -c "https://clickhouse-builds.s3.yandex.net/$PR_TO_TEST/$SHA_TO_TEST/clickhouse_build_check/clang-10_debug_none_bundled_unsplitted_disable_False_binary/clickhouse" chmod +x clickhouse + ln -s ./clickhouse ./clickhouse-server + ln -s ./clickhouse ./clickhouse-client } function configure @@ -54,30 +56,57 @@ function watchdog sleep 3600 echo "Fuzzing run has timed out" - ./clickhouse client --query "select elapsed, query from system.processes" ||: - killall -9 clickhouse clickhouse-server clickhouse-client ||: + killall clickhouse-client ||: + for x in {1..10} + do + if ! pgrep -f clickhouse-client + then + break + fi + sleep 1 + done + + ./clickhouse-client --query "select elapsed, query from system.processes" ||: + + killall clickhouse-server ||: + for x in {1..10} + do + if ! pgrep -f clickhouse-server + then + break + fi + sleep 1 + done + + killall -9 clickhouse-server clickhouse-client ||: } function fuzz { - ./clickhouse server --config-file db/config.xml -- --path db 2>&1 | tail -100000 > server.log & + ./clickhouse-server --config-file db/config.xml -- --path db 2>&1 | tail -100000 > server.log & server_pid=$! kill -0 $server_pid - while ! ./clickhouse client --query "select 1" && kill -0 $server_pid ; do echo . ; sleep 1 ; done - ./clickhouse client --query "select 1" + while ! ./clickhouse-client --query "select 1" && kill -0 $server_pid ; do echo . ; sleep 1 ; done + ./clickhouse-client --query "select 1" kill -0 $server_pid echo Server started fuzzer_exit_code=0 - ./clickhouse client --query-fuzzer-runs=1000 \ + ./clickhouse-client --query-fuzzer-runs=1000 \ < <(for f in $(ls ch/tests/queries/0_stateless/*.sql | sort -R); do cat "$f"; echo ';'; done) \ > >(tail -100000 > fuzzer.log) \ 2>&1 \ || fuzzer_exit_code=$? echo "Fuzzer exit code is $fuzzer_exit_code" - ./clickhouse client --query "select elapsed, query from system.processes" ||: + ./clickhouse-client --query "select elapsed, query from system.processes" ||: kill -9 $server_pid ||: + + if [ "$fuzzer_exit_code" == "137" ] + then + # Killed by watchdog, meaning, no errors. + return 0 + fi return $fuzzer_exit_code } @@ -106,11 +135,19 @@ case "$stage" in time configure ;& "fuzz") + # Start a watchdog that should kill the fuzzer on timeout. + # The shell won't kill the child sleep when we kill it, so we have to put it + # into a separate process group so that we can kill them all. + set -m watchdog & watchdog_pid=$! + set +m + # Check that the watchdog has started + kill -0 $watchdog_pid + fuzzer_exit_code=0 time fuzz || fuzzer_exit_code=$? - kill $watchdog_pid ||: + kill -- -$watchdog_pid ||: # Debug date @@ -118,6 +155,19 @@ case "$stage" in jobs pstree -aspgT + # Make files with status and description we'll show for this check on Github + if [ "$fuzzer_exit_code" == 0 ] + then + echo "OK" > description.txt + echo "success" > status.txt + else + echo "failure" > status.txt + if ! grep -m2 "received signal \|Logical error" server-log.txt > description.txt + then + echo "Fuzzer exit code $fuzzer_exit_code. See the logs" > description.txt + fi + fi + exit $fuzzer_exit_code ;& esac diff --git a/programs/client/Client.cpp b/programs/client/Client.cpp index 6a95cbfb72..797342a1b4 100644 --- a/programs/client/Client.cpp +++ b/programs/client/Client.cpp @@ -216,7 +216,7 @@ private: ConnectionParameters connection_parameters; QueryFuzzer fuzzer; - int query_fuzzer_runs; + int query_fuzzer_runs = 0; void initialize(Poco::Util::Application & self) override { @@ -1041,10 +1041,12 @@ private: begin - text.data()); ASTPtr fuzz_base = orig_ast; - for (int fuzz_step = 0; fuzz_step < query_fuzzer_runs; fuzz_step++) + // Don't repeat inserts, the tables grow too big. + const int this_query_runs = as_insert ? 1 : query_fuzzer_runs; + for (int fuzz_step = 0; fuzz_step < this_query_runs; fuzz_step++) { - fprintf(stderr, "fuzzing step %d for query at pos %zd\n", - fuzz_step, this_query_begin - text.data()); + fprintf(stderr, "fuzzing step %d out of %d for query at pos %zd\n", + fuzz_step, this_query_runs, this_query_begin - text.data()); ASTPtr ast_to_process; try @@ -1058,7 +1060,11 @@ private: std::stringstream dump_of_cloned_ast; ast_to_process->dumpTree(dump_of_cloned_ast); - fuzzer.fuzzMain(ast_to_process); + // Run the original query as well. + if (fuzz_step > 0) + { + fuzzer.fuzzMain(ast_to_process); + } auto base_after_fuzz = fuzz_base->formatForErrorMessage(); diff --git a/src/Functions/FunctionsLogical.cpp b/src/Functions/FunctionsLogical.cpp index 029e3c8128..9419696ef9 100644 --- a/src/Functions/FunctionsLogical.cpp +++ b/src/Functions/FunctionsLogical.cpp @@ -222,7 +222,7 @@ struct ValueGetterBuilderImpl<> static TernaryValueGetter build(const IColumn * x) { throw Exception( - std::string("Unknown numeric column of type: ") + demangle(typeid(x).name()), + std::string("Unknown numeric column of type: ") + demangle(typeid(*x).name()), ErrorCodes::LOGICAL_ERROR); } }; -- GitLab