[COMMIT scylladb master] Merge 'test: auth: add random tag to resources in test_auth_v2_migration' from Marcin Maliszkiewicz

0 views
Skip to first unread message

Commit Bot

<bot@cloudius-systems.com>
unread,
Jun 27, 2024, 5:12:26 PMJun 27
to scylladb-dev@googlegroups.com, Piotr Dulikowski
From: Piotr Dulikowski <pio...@scylladb.com>
Committer: Piotr Dulikowski <pio...@scylladb.com>
Branch: master

Merge 'test: auth: add random tag to resources in test_auth_v2_migration' from Marcin Maliszkiewicz

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

backport: no, just a test fix

Closes scylladb/scylladb#19484

* github.com:scylladb/scylladb:
test: auth: add random tag to resources in test_auth_v2_migration
test: extend unique_name with random sufix

---
diff --git a/test/auth_cluster/test_auth_v2_migration.py b/test/auth_cluster/test_auth_v2_migration.py
--- 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
diff --git a/test/pylib/util.py b/test/pylib/util.py
--- a/test/pylib/util.py
+++ b/test/pylib/util.py
@@ -10,6 +10,8 @@
import pathlib
import os
import pytest
+import random
+import string

from typing import Callable, Awaitable, Optional, TypeVar, Any

@@ -29,19 +31,18 @@ def process(self, msg, kwargs):
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))
# If unique_name() is called twice in the same millisecond...
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(
Reply all
Reply to author
Forward
0 new messages