2022-03-31 18:16:51 +00:00
|
|
|
#!/usr/bin/env bash
|
2022-05-12 08:51:25 +00:00
|
|
|
# Tags: race, no-fasttest, no-parallel, no-backward-compatibility-check
|
2022-03-31 18:16:51 +00:00
|
|
|
|
|
|
|
# Test tries to reproduce a race between threads:
|
|
|
|
# - deletes user
|
|
|
|
# - creates user
|
|
|
|
# - uses it as session user
|
|
|
|
# - apply role to the user
|
|
|
|
#
|
|
|
|
# https://github.com/ClickHouse/ClickHouse/issues/35714
|
|
|
|
|
|
|
|
set -e
|
|
|
|
|
|
|
|
CURDIR=$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)
|
|
|
|
# shellcheck source=../shell_config.sh
|
|
|
|
. "$CURDIR"/../shell_config.sh
|
|
|
|
# shellcheck source=./replication.lib
|
|
|
|
. "$CURDIR"/replication.lib
|
|
|
|
|
|
|
|
#export PS4='\nDEBUG level:$SHLVL subshell-level: $BASH_SUBSHELL \nsource-file:${BASH_SOURCE} line#:${LINENO} function:${FUNCNAME[0]:+${FUNCNAME[0]}(): }\nstatement: '
|
|
|
|
|
|
|
|
|
|
|
|
$CLICKHOUSE_CLIENT -nm -q "
|
|
|
|
DROP ROLE IF EXISTS test_role_02242;
|
|
|
|
CREATE ROLE test_role_02242;
|
|
|
|
"
|
|
|
|
|
|
|
|
function delete_user()
|
|
|
|
{
|
2022-04-28 07:18:00 +00:00
|
|
|
$CLICKHOUSE_CLIENT -q "DROP USER IF EXISTS test_user_02242" ||:
|
2022-03-31 18:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function create_and_login_user()
|
|
|
|
{
|
2022-04-28 07:18:00 +00:00
|
|
|
$CLICKHOUSE_CLIENT -q "CREATE USER IF NOT EXISTS test_user_02242" ||:
|
|
|
|
$CLICKHOUSE_CLIENT -u "test_user_02242" -q "SELECT COUNT(*) FROM system.session_log WHERE user == 'test_user_02242'" > /dev/null ||:
|
2022-03-31 18:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
function set_role()
|
|
|
|
{
|
2022-04-28 07:18:00 +00:00
|
|
|
$CLICKHOUSE_CLIENT -q "SET ROLE test_role_02242 TO test_user_02242" ||:
|
2022-03-31 18:16:51 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
export -f delete_user
|
|
|
|
export -f create_and_login_user
|
|
|
|
export -f set_role
|
|
|
|
|
2022-04-27 12:35:58 +00:00
|
|
|
TIMEOUT=10
|
2022-03-31 18:16:51 +00:00
|
|
|
|
2022-04-01 12:32:53 +00:00
|
|
|
for (( i = 0 ; i < 100; ++i ))
|
2022-03-31 18:16:51 +00:00
|
|
|
do
|
|
|
|
clickhouse_client_loop_timeout $TIMEOUT create_and_login_user 2> /dev/null &
|
|
|
|
clickhouse_client_loop_timeout $TIMEOUT delete_user 2> /dev/null &
|
|
|
|
clickhouse_client_loop_timeout $TIMEOUT set_role 2> /dev/null &
|
|
|
|
done
|
|
|
|
|
|
|
|
wait
|
|
|
|
|
|
|
|
# $CLICKHOUSE_CLIENT -q "DROP ROLE IF EXISTS test_role_02242"
|
|
|
|
# $CLICKHOUSE_CLIENT -q "DROP USER IF EXISTS test_user_02242"
|
|
|
|
|
|
|
|
# wait
|