Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix (pytest): generate unique random dbfilename for tests #3317

Merged
merged 1 commit into from
Jul 15, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 6 additions & 10 deletions tests/dragonfly/replication_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -1210,8 +1210,9 @@ async def delayed_takeover():
async def test_take_over_seeder(
request, df_factory, df_seeder_factory, master_threads, replica_threads
):
tmp_file_name = "".join(random.choices(string.ascii_letters, k=10))
master = df_factory.create(proactor_threads=master_threads, dbfilename=f"dump_{tmp_file_name}")
master = df_factory.create(
proactor_threads=master_threads, dbfilename=f"dump_{tmp_file_name()}"
)
replica = df_factory.create(proactor_threads=replica_threads)
df_factory.start_all([master, replica])

Expand Down Expand Up @@ -1884,9 +1885,8 @@ async def test_client_pause_with_replica(df_factory, df_seeder_factory):


async def test_replicaof_reject_on_load(df_factory, df_seeder_factory):
tmp_file_name = "".join(random.choices(string.ascii_letters, k=10))
master = df_factory.create()
replica = df_factory.create(dbfilename=f"dump_{tmp_file_name}")
replica = df_factory.create(dbfilename=f"dump_{tmp_file_name()}")
df_factory.start_all([master, replica])

seeder = SeederV2(key_target=40000)
Expand Down Expand Up @@ -2052,10 +2052,8 @@ async def send_setex():

@pytest.mark.asyncio
async def test_saving_replica(df_factory):
tmp_file_name = "".join(random.choices(string.ascii_letters, k=10))

master = df_factory.create(proactor_threads=1)
replica = df_factory.create(proactor_threads=1, dbfilename=f"dump_{tmp_file_name}")
replica = df_factory.create(proactor_threads=1, dbfilename=f"dump_{tmp_file_name()}")
df_factory.start_all([master, replica])

c_master = master.client()
Expand Down Expand Up @@ -2084,10 +2082,8 @@ async def save_replica():

@pytest.mark.asyncio
async def test_start_replicating_while_save(df_factory):
tmp_file_name = "".join(random.choices(string.ascii_letters, k=10))

master = df_factory.create(proactor_threads=4)
replica = df_factory.create(proactor_threads=4, dbfilename=f"dump_{tmp_file_name}")
replica = df_factory.create(proactor_threads=4, dbfilename=f"dump_{tmp_file_name()}")
df_factory.start_all([master, replica])

c_master = master.client()
Expand Down
7 changes: 3 additions & 4 deletions tests/dragonfly/snapshot_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
from random import randint as rand

from . import dfly_args
from .utility import wait_available_async, chunked, is_saving
from .utility import wait_available_async, is_saving, tmp_file_name

from .seeder import StaticSeeder

Expand Down Expand Up @@ -43,7 +43,7 @@ async def test_consistency(df_factory, format: str, seeder_opts: dict):
"""
Test consistency over a large variety of data with different sizes
"""
dbfilename = f"test-consistency{rand(0, 5000)}"
dbfilename = f"dump_{tmp_file_name()}"
instance = df_factory.create(dbfilename=dbfilename)
instance.start()
async_client = instance.client()
Expand Down Expand Up @@ -376,8 +376,7 @@ async def test_snapshot(self, df_server, async_client):
@pytest.mark.parametrize("format", FILE_FORMATS)
@dfly_args({**BASIC_ARGS, "dbfilename": "info-while-snapshot"})
async def test_infomemory_while_snapshoting(df_factory, format: str):
dbfilename = f"test-consistency{rand(0, 5000)}"
instance = df_factory.create(dbfilename=dbfilename)
instance = df_factory.create(dbfilename=f"dump_{tmp_file_name()}")
instance.start()
async_client = instance.client()
await async_client.execute_command("DEBUG POPULATE 10000 key 4048 RAND")
Expand Down
4 changes: 4 additions & 0 deletions tests/dragonfly/utility.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@
from enum import Enum


def tmp_file_name():
return "".join(random.choices(string.ascii_letters, k=10))


def chunked(n, iterable):
"""Transform iterable into iterator of chunks of size n"""
it = iter(iterable)
Expand Down
Loading