ClickHouse/tests/queries/0_stateless/transactions.lib
Alexander Tokmakov a15444031c add test
2021-12-20 21:53:05 +03:00

49 lines
1.3 KiB
Bash
Executable File

#!/usr/bin/env bash
# Useful to run
function tx()
{
tx_num=$1
query=$2
session="${CLICKHOUSE_TEST_ZOOKEEPER_PREFIX}_tx$tx_num"
query_id="${session}_${RANDOM}"
url_without_session="https://${CLICKHOUSE_HOST}:${CLICKHOUSE_PORT_HTTPS}/?"
url="${url_without_session}session_id=$session&query_id=$query_id&database=$CLICKHOUSE_DATABASE"
${CLICKHOUSE_CURL} -m 60 -sSk "$url" --data "$query" | sed "s/^/tx$tx_num\t/"
}
function tx_wait() {
tx_num=$1
session="${CLICKHOUSE_TEST_ZOOKEEPER_PREFIX}_tx$tx_num"
# wait for previous query in transaction
count=0
while [[ $($CLICKHOUSE_CLIENT -q "SELECT count() FROM system.processes WHERE query_id LIKE '$session%'") -gt 0 ]]; do
sleep 0.5
count=$((count+1))
if [ "$count" -gt 120 ]; then
echo "timeout while waiting for $tx_num"
break
fi
done;
}
function tx_async()
{
tx_num=$1
query=$2
tx_wait $tx_num
session="${CLICKHOUSE_TEST_ZOOKEEPER_PREFIX}_tx$tx_num"
query_id="${session}_${RANDOM}"
url_without_session="https://${CLICKHOUSE_HOST}:${CLICKHOUSE_PORT_HTTPS}/?"
url="${url_without_session}session_id=$session&query_id=$query_id&database=$CLICKHOUSE_DATABASE"
# run query asynchronously
${CLICKHOUSE_CURL} -m 60 -sSk "$url" --data "$query" | sed "s/^/tx$tx_num\t/" &
}