ClickHouse/dbms/tests/queries/0_stateless/00600_replace_running_query.sh

41 lines
1.6 KiB
Bash
Raw Normal View History

2018-03-09 23:07:08 +00:00
#!/usr/bin/env bash
2019-08-22 21:35:16 +00:00
CLICKHOUSE_CLIENT_SERVER_LOGS_LEVEL=none
2018-03-09 23:07:08 +00:00
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
. $CURDIR/../shell_config.sh
2019-07-20 00:47:06 +00:00
function wait_for_query_to_start()
{
while [[ $($CLICKHOUSE_CURL -sS "$CLICKHOUSE_URL" -d "SELECT count() FROM system.processes WHERE query_id = '$1'") == 0 ]]; do sleep 0.1; done
}
2019-08-22 21:35:16 +00:00
$CLICKHOUSE_CURL -sS "$CLICKHOUSE_URL?query_id=hello&replace_running_query=1" -d 'SELECT 1, count() FROM system.numbers' 2>&1 > /dev/null &
2019-07-20 00:47:06 +00:00
wait_for_query_to_start 'hello'
# Replace it
$CLICKHOUSE_CURL -sS "$CLICKHOUSE_URL?query_id=hello&replace_running_query=1" -d 'SELECT 0'
2019-07-20 00:47:06 +00:00
# Wait for it to be replaced
2018-03-09 23:07:08 +00:00
wait
2019-08-22 21:35:16 +00:00
${CLICKHOUSE_CLIENT} --user=readonly --query_id=42 --query='SELECT 2, count() FROM system.numbers' 2>&1 | grep -cF 'was cancelled' &
2019-07-20 00:47:06 +00:00
wait_for_query_to_start '42'
2019-08-22 21:35:16 +00:00
# Trying to run another query with the same query_id
${CLICKHOUSE_CLIENT} --query_id=42 --query='SELECT 43' 2>&1 | grep -cF 'is already running by user'
# Trying to replace query of a different user
$CLICKHOUSE_CURL -sS "$CLICKHOUSE_URL?query_id=42&replace_running_query=1" -d 'SELECT 1' | grep -cF 'is already running by user'
$CLICKHOUSE_CURL -sS "$CLICKHOUSE_URL" -d "KILL QUERY WHERE query_id = '42' SYNC"
wait
2019-08-22 21:35:16 +00:00
${CLICKHOUSE_CLIENT} --query_id=42 --query='SELECT 3, count() FROM system.numbers' 2>&1 | grep -cF 'was cancelled' &
2019-07-20 00:47:06 +00:00
wait_for_query_to_start '42'
2019-08-22 21:35:16 +00:00
${CLICKHOUSE_CLIENT} --query_id=42 --replace_running_query=1 --queue_max_wait_ms=500 --query='SELECT 43' 2>&1 | grep -F "can't be stopped" > /dev/null
${CLICKHOUSE_CLIENT} --query_id=42 --replace_running_query=1 --query='SELECT 44'
wait