From d08a80b34ff78511528a40cd7c0946251bd78d9b Mon Sep 17 00:00:00 2001 From: Marcin Maliszkiewicz Date: Wed, 26 Jun 2024 14:15:27 +0200 Subject: [PATCH 1/2] test: extend unique_name with random sufix This reduces collision risk in an unlikely and incorrect setup where tests would be run concurrently by multiple processes. --- test/pylib/util.py | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/test/pylib/util.py b/test/pylib/util.py index 1dc2545378..63a2e9f536 100644 --- a/test/pylib/util.py +++ b/test/pylib/util.py @@ -10,6 +10,8 @@ import logging import pathlib import os import pytest +import random +import string from typing import Callable, Awaitable, Optional, TypeVar, Any @@ -29,11 +31,10 @@ class LogPrefixAdapter(logging.LoggerAdapter): return '[%s] %s' % (self.extra['prefix'], msg), kwargs -unique_name_prefix = 'test_' T = TypeVar('T') -def unique_name(): +def unique_name(unique_name_prefix = 'test_'): if not hasattr(unique_name, "last_ms"): unique_name.last_ms = 0 current_ms = int(round(time.time() * 1000)) @@ -41,7 +42,7 @@ def unique_name(): if unique_name.last_ms >= current_ms: current_ms = unique_name.last_ms + 1 unique_name.last_ms = current_ms - return unique_name_prefix + str(current_ms) + return unique_name_prefix + str(current_ms) + '_' + ''.join(random.choice(string.ascii_lowercase) for _ in range(5)) async def wait_for( From b708c5701f83292cc8364cfdc0b791935968669b Mon Sep 17 00:00:00 2001 From: Marcin Maliszkiewicz Date: Tue, 25 Jun 2024 12:07:27 +0200 Subject: [PATCH 2/2] test: auth: add random tag to resources in test_auth_v2_migration Those tests are sometimes failing on CI and we have two hypothesis: 1. Something wrong with consistency of statements 2. Interruption from another test run (e.g. same queries performed concurrently or data remained after previous run) To exclude or confirm 2. we add random marker to avoid potential collision, in such case it will be clearly visible that wrong data comes from a different run. Related scylladb/scylladb#18931 Related scylladb/scylladb#18319 --- test/auth_cluster/test_auth_v2_migration.py | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/test/auth_cluster/test_auth_v2_migration.py b/test/auth_cluster/test_auth_v2_migration.py index 9323521fbe..85b96bd731 100644 --- a/test/auth_cluster/test_auth_v2_migration.py +++ b/test/auth_cluster/test_auth_v2_migration.py @@ -53,17 +53,19 @@ async def populate_test_data(manager: ManagerClient, data): async def populate_auth_v1_data(manager: ManagerClient): await populate_test_data(manager, auth_data()) # test also absence of deleted data + username = unique_name("deleted_user_") + logging.info(f"Creating deleted auth-v1 user: {username}") await populate_test_data(manager, [ { "statement": "INSERT INTO system_auth.roles (role, can_login, is_superuser, member_of, salted_hash) VALUES (?, ?, ?, ?, ?)", "rows": [ - ("deleted_user", True, False, None, "fefe"), + (username, True, False, None, "fefe"), ] }, { "statement": "DELETE FROM system_auth.roles WHERE role = ?", "rows": [ - ("deleted_user",), + (username,), ] }, ]) @@ -123,14 +125,16 @@ async def check_auth_v2_works(manager: ManagerClient, hosts): assert len(user1_roles) == 2 assert set([user1_roles[0].role, user1_roles[1].role]) == set(["users", "user 1"]) - await cql.run_async("CREATE ROLE user_after_migration") + username = unique_name("user_after_migration_") + logging.info(f"Create role after migration: {username}") + await cql.run_async(f"CREATE ROLE {username}") await asyncio.gather(*(read_barrier(cql, host) for host in hosts)) # see warmup_v1_static_values for background about checks below # check if it was added to a new table - assert len(await cql.run_async("SELECT role FROM system.roles WHERE role = 'user_after_migration'")) == 1 + assert len(await cql.run_async(f"SELECT role FROM system.roles WHERE role = '{username}'")) == 1 # check whether list roles statement sees it also via new table (on all nodes) - await asyncio.gather(*(cql.run_async("LIST ROLES OF user_after_migration", host=host) for host in hosts)) - await cql.run_async("DROP ROLE user_after_migration") + await asyncio.gather(*(cql.run_async(f"LIST ROLES OF {username}", host=host) for host in hosts)) + await cql.run_async(f"DROP ROLE {username}") @pytest.mark.asyncio