tests: fix 01676_clickhouse_client_autocomplete

Previusly it works incorrectly, timeout does not work when some stdin
attached for expect, and so the test was wrong.

Also this test requires small timeout since it waits in the loop until
the completion will be loaded.

So to make the test more clean, add a message when is_done is set to 1,
and update the reference file.

And also cleanup the test to reduce copy-paste.

Signed-off-by: Azat Khuzhin <a.khuzhin@semrush.com>
This commit is contained in:
Azat Khuzhin 2022-11-30 10:37:25 +01:00
parent 0b48a2ed5e
commit b514300cee
2 changed files with 44 additions and 59 deletions

View File

@ -0,0 +1,21 @@
# clickhouse-client
concatAssumeInjective: OK
ReplacingMergeTree: OK
JSONEachRow: OK
clusterAllReplicas: OK
SimpleAggregateFunction: OK
write_ahead_log_interval_ms_to_fsync: OK
max_concurrent_queries_for_all_users: OK
test_shard_localhost: OK
default_path_test: OK
default: OK
uniqCombined64ForEach: OK
system: OK
aggregate_function_combinators: OK
primary_key_bytes_in_memory_allocated: OK
# clickhouse-local
concatAssumeInjective: OK
ReplacingMergeTree: OK
JSONEachRow: OK
clusterAllReplicas: OK
SimpleAggregateFunction: OK

View File

@ -5,9 +5,11 @@ CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
# shellcheck source=../shell_config.sh # shellcheck source=../shell_config.sh
. "$CURDIR"/../shell_config.sh . "$CURDIR"/../shell_config.sh
SCRIPT_PATH="$CURDIR/$CLICKHOUSE_TEST_UNIQUE_NAME.generated-expect"
# NOTE: database = $CLICKHOUSE_DATABASE is superfluous # NOTE: database = $CLICKHOUSE_DATABASE is superfluous
function test_completion_word_client() function test_completion_word()
{ {
local w=$1 && shift local w=$1 && shift
@ -15,13 +17,16 @@ function test_completion_word_client()
local compword_begin=${w:0:$((w_len-3))} local compword_begin=${w:0:$((w_len-3))}
local compword_end=${w:$((w_len-3))} local compword_end=${w:$((w_len-3))}
# NOTE: here and below you should escape variables of the expect. # NOTE:
timeout 60s expect << EOF # - here and below you should escape variables of the expect.
# - you should not use "expect <<..." since in this case timeout/eof will
# not work (I guess due to attached stdin)
cat > "$SCRIPT_PATH" << EOF
# NOTE: log will be appended # NOTE: log will be appended
exp_internal -f $CLICKHOUSE_TMP/$(basename "${BASH_SOURCE[0]}").debuglog 0 exp_internal -f $CLICKHOUSE_TMP/$(basename "${BASH_SOURCE[0]}").debuglog 0
log_user 0 log_user 0
set timeout 3 set timeout 60
match_max 100000 match_max 100000
expect_after { expect_after {
# Do not ignore eof from expect # Do not ignore eof from expect
@ -30,7 +35,7 @@ expect_after {
timeout { exit 1 } timeout { exit 1 }
} }
spawn bash -c "$CLICKHOUSE_CLIENT_BINARY $CLICKHOUSE_CLIENT_OPT" spawn bash -c "$*"
expect ":) " expect ":) "
# Make a query # Make a query
@ -39,10 +44,12 @@ expect "SET $compword_begin"
# Wait for suggestions to load, they are loaded in background # Wait for suggestions to load, they are loaded in background
set is_done 0 set is_done 0
set timeout 1
while {\$is_done == 0} { while {\$is_done == 0} {
send -- "\\t" send -- "\\t"
expect { expect {
"$compword_begin$compword_end" { "$compword_begin$compword_end" {
puts "$compword_begin$compword_end: OK"
set is_done 1 set is_done 1
} }
default { default {
@ -54,6 +61,10 @@ while {\$is_done == 0} {
send -- "\\3\\4" send -- "\\3\\4"
expect eof expect eof
EOF EOF
# NOTE: run expect under timeout since there is while loop that is not
# limited with timeout.
timeout 2m expect -f "$SCRIPT_PATH"
} }
# last 3 bytes will be completed, # last 3 bytes will be completed,
@ -93,56 +104,6 @@ client_compwords_positive=(
# FIXME: none # FIXME: none
) )
function test_completion_word_local()
{
local w=$1 && shift
local w_len=${#w}
local compword_begin=${w:0:$((w_len-3))}
local compword_end=${w:$((w_len-3))}
# NOTE: here and below you should escape variables of the expect.
timeout 60s expect << EOF
# NOTE: log will be appended
exp_internal -f $CLICKHOUSE_TMP/$(basename "${BASH_SOURCE[0]}").debuglog 0
log_user 0
set timeout 3
match_max 100000
expect_after {
# Do not ignore eof from expect
eof { exp_continue }
# A default timeout action is to do nothing, change it to fail
timeout { exit 1 }
}
spawn bash -c "$CLICKHOUSE_LOCAL"
expect ":) "
# Make a query
send -- "SET $compword_begin"
expect "SET $compword_begin"
# Wait for suggestions to load, they are loaded in background
set is_done 0
while {\$is_done == 0} {
send -- "\\t"
expect {
"$compword_begin$compword_end" {
set is_done 1
}
default {
sleep 1
}
}
}
send -- "\\3\\4"
expect eof
EOF
}
local_compwords_positive=( local_compwords_positive=(
# system.functions # system.functions
concatAssumeInjective concatAssumeInjective
@ -156,12 +117,15 @@ local_compwords_positive=(
SimpleAggregateFunction SimpleAggregateFunction
) )
echo "# clickhouse-client"
for w in "${client_compwords_positive[@]}"; do for w in "${client_compwords_positive[@]}"; do
test_completion_word_client "$w" || echo "[FAIL] $w (positive)" test_completion_word "$w" "$CLICKHOUSE_CLIENT"
done
echo "# clickhouse-local"
for w in "${local_compwords_positive[@]}"; do
test_completion_word "$w" "$CLICKHOUSE_LOCAL"
done done
for w in "${local_compwords_positive[@]}"; do rm -f "${SCRIPT_PATH:?}"
test_completion_word_local "$w" || echo "[FAIL] $w (positive)"
done
exit 0 exit 0