[COMMIT scylladb master] test: extend unique_name with random sufix

0 views
Skip to first unread message

Commit Bot

<bot@cloudius-systems.com>
unread,
Jun 27, 2024, 5:12:23 PMJun 27
to scylladb-dev@googlegroups.com, Marcin Maliszkiewicz
From: Marcin Maliszkiewicz <marc...@scylladb.com>
Committer: Marcin Maliszkiewicz <marc...@scylladb.com>
Branch: master

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.

---
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