Skip to content

Commit

Permalink
Used timeout function instead of undefined clickhouse_client_loop_tim…
Browse files Browse the repository at this point in the history
…eout in functional tests (#51923)

* removed undefined clickhouse_client_loop_timeout

* test fix and improvement

* Changes after review iteration
  • Loading branch information
Demilivor committed Jul 11, 2023
1 parent 627e924 commit 49c1beb
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 16 deletions.
27 changes: 17 additions & 10 deletions tests/queries/0_stateless/02242_delete_user_race.sh
Original file line number Diff line number Diff line change
Expand Up @@ -22,18 +22,27 @@ $CLICKHOUSE_CLIENT -nm -q "

function delete_user()
{
$CLICKHOUSE_CLIENT -q "DROP USER IF EXISTS test_user_02242" ||:
while true; do
$CLICKHOUSE_CLIENT -q "DROP USER IF EXISTS test_user_02242" ||:
sleep 0.$RANDOM;
done
}

function create_and_login_user()
{
$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 ||:
while true; do
$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 ||:
sleep 0.$RANDOM;
done
}

function set_role()
{
$CLICKHOUSE_CLIENT -q "SET ROLE test_role_02242 TO test_user_02242" ||:
while true; do
$CLICKHOUSE_CLIENT -q "SET DEFAULT ROLE test_role_02242 TO test_user_02242" ||:
sleep 0.$RANDOM;
done
}

export -f delete_user
Expand All @@ -42,12 +51,10 @@ export -f set_role

TIMEOUT=10

for (( i = 0 ; i < 100; ++i ))
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

timeout $TIMEOUT bash -c create_and_login_user 2> /dev/null &
timeout $TIMEOUT bash -c delete_user 2> /dev/null &
timeout $TIMEOUT bash -c set_role 2> /dev/null &

wait

Expand Down
13 changes: 7 additions & 6 deletions tests/queries/0_stateless/02243_drop_user_grant_race.sh
Original file line number Diff line number Diff line change
Expand Up @@ -19,17 +19,18 @@ $CLICKHOUSE_CLIENT -nm -q "

function create_drop_grant()
{
$CLICKHOUSE_CLIENT -q "CREATE USER IF NOT EXISTS test_user_02243 GRANTEES NONE" ||:
$CLICKHOUSE_CLIENT -q "GRANT ALL ON *.* TO test_user_02243 WITH GRANT OPTION" ||:
$CLICKHOUSE_CLIENT -q "DROP USER IF EXISTS test_user_02243" &
$CLICKHOUSE_CLIENT --user test_user_02243 -q "GRANT ALL ON *.* TO kek_02243" &
wait
while true; do
$CLICKHOUSE_CLIENT -q "CREATE USER IF NOT EXISTS test_user_02243 GRANTEES NONE" ||:
$CLICKHOUSE_CLIENT -q "GRANT ALL ON *.* TO test_user_02243 WITH GRANT OPTION" ||:
$CLICKHOUSE_CLIENT -q "DROP USER IF EXISTS test_user_02243" &
$CLICKHOUSE_CLIENT --user test_user_02243 -q "GRANT ALL ON *.* TO kek_02243" &
done
}

export -f create_drop_grant

TIMEOUT=10
clickhouse_client_loop_timeout $TIMEOUT create_drop_grant 2> /dev/null &
timeout $TIMEOUT bash -c create_drop_grant 2> /dev/null &
wait

$CLICKHOUSE_CLIENT --user kek_02243 -q "SELECT * FROM test" 2>&1| grep -Fa "Exception: " | grep -Eo ACCESS_DENIED | uniq
Expand Down

0 comments on commit 49c1beb

Please sign in to comment.