2022-08-26 10:54:38 +00:00
|
|
|
import time
|
|
|
|
import pytest
|
2022-10-24 18:22:43 +00:00
|
|
|
import os
|
|
|
|
import glob
|
2022-08-26 10:54:38 +00:00
|
|
|
from pathlib import Path
|
2022-11-06 14:27:43 +00:00
|
|
|
|
|
|
|
from . import dfly_args
|
2023-01-09 20:31:15 +00:00
|
|
|
from .utility import DflySeeder, wait_available_async
|
2022-08-26 10:54:38 +00:00
|
|
|
|
2022-10-31 14:39:20 +00:00
|
|
|
BASIC_ARGS = {"dir": "{DRAGONFLY_TMP}/"}
|
2023-01-09 20:31:15 +00:00
|
|
|
|
2023-01-12 11:38:05 +00:00
|
|
|
SEEDER_ARGS = dict(keys=12_000, dbcount=5, multi_transaction_probability=0)
|
2022-10-24 18:22:43 +00:00
|
|
|
|
|
|
|
|
|
|
|
class SnapshotTestBase:
|
2022-08-26 10:54:38 +00:00
|
|
|
def setup(self, tmp_dir: Path):
|
2022-10-24 18:22:43 +00:00
|
|
|
self.tmp_dir = tmp_dir
|
2022-08-26 10:54:38 +00:00
|
|
|
|
2022-10-24 18:22:43 +00:00
|
|
|
def get_main_file(self, suffix):
|
|
|
|
def is_main(f): return "summary" in f if suffix == "dfs" else True
|
|
|
|
files = glob.glob(str(self.tmp_dir.absolute()) + '/test-*.'+suffix)
|
|
|
|
return next(f for f in sorted(files) if is_main(f))
|
|
|
|
|
|
|
|
|
2023-01-09 20:31:15 +00:00
|
|
|
@dfly_args({**BASIC_ARGS, "dbfilename": "test-rdb"})
|
2022-10-24 18:22:43 +00:00
|
|
|
class TestRdbSnapshot(SnapshotTestBase):
|
|
|
|
"""Test single file rdb snapshot"""
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def setup(self, tmp_dir: Path):
|
|
|
|
super().setup(tmp_dir)
|
|
|
|
|
2023-01-09 20:31:15 +00:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_snapshot(self, df_seeder_factory, async_client, df_server):
|
|
|
|
seeder = df_seeder_factory.create(port=df_server.port, **SEEDER_ARGS)
|
|
|
|
await seeder.run(target_deviation=0.1)
|
|
|
|
|
|
|
|
start_capture = await seeder.capture()
|
2022-10-24 18:22:43 +00:00
|
|
|
|
|
|
|
# save + flush + load
|
2023-02-15 08:15:38 +00:00
|
|
|
await async_client.execute_command("SAVE RDB")
|
2023-01-09 20:31:15 +00:00
|
|
|
assert await async_client.flushall()
|
|
|
|
await async_client.execute_command("DEBUG LOAD " + super().get_main_file("rdb"))
|
2022-10-24 18:22:43 +00:00
|
|
|
|
2023-01-09 20:31:15 +00:00
|
|
|
assert await seeder.compare(start_capture)
|
2022-10-24 18:22:43 +00:00
|
|
|
|
2022-10-31 14:39:20 +00:00
|
|
|
|
2023-01-09 20:31:15 +00:00
|
|
|
@dfly_args({**BASIC_ARGS, "dbfilename": "test-dfs"})
|
2022-10-24 18:22:43 +00:00
|
|
|
class TestDflySnapshot(SnapshotTestBase):
|
|
|
|
"""Test multi file snapshot"""
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def setup(self, tmp_dir: Path):
|
|
|
|
self.tmp_dir = tmp_dir
|
|
|
|
|
2023-01-09 20:31:15 +00:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_snapshot(self, df_seeder_factory, async_client, df_server):
|
|
|
|
seeder = df_seeder_factory.create(port=df_server.port, **SEEDER_ARGS)
|
|
|
|
await seeder.run(target_deviation=0.1)
|
|
|
|
|
|
|
|
start_capture = await seeder.capture()
|
2022-10-24 18:22:43 +00:00
|
|
|
|
|
|
|
# save + flush + load
|
2023-01-09 20:31:15 +00:00
|
|
|
await async_client.execute_command("SAVE DF")
|
|
|
|
assert await async_client.flushall()
|
|
|
|
await async_client.execute_command("DEBUG LOAD " + super().get_main_file("dfs"))
|
2022-10-24 18:22:43 +00:00
|
|
|
|
2023-01-09 20:31:15 +00:00
|
|
|
assert await seeder.compare(start_capture)
|
2022-10-24 18:22:43 +00:00
|
|
|
|
|
|
|
|
2023-02-15 09:12:41 +00:00
|
|
|
@dfly_args({**BASIC_ARGS, "dbfilename": "test-periodic.dfs", "save_schedule": "*:*"})
|
2022-10-24 18:22:43 +00:00
|
|
|
class TestPeriodicSnapshot(SnapshotTestBase):
|
|
|
|
"""Test periodic snapshotting"""
|
|
|
|
@pytest.fixture(autouse=True)
|
|
|
|
def setup(self, tmp_dir: Path):
|
|
|
|
super().setup(tmp_dir)
|
|
|
|
|
2023-01-09 20:31:15 +00:00
|
|
|
@pytest.mark.asyncio
|
|
|
|
async def test_snapshot(self, df_seeder_factory, df_server):
|
2023-01-12 11:38:05 +00:00
|
|
|
seeder = df_seeder_factory.create(port=df_server.port, keys=10, multi_transaction_probability=0)
|
2023-01-09 20:31:15 +00:00
|
|
|
await seeder.run(target_deviation=0.5)
|
2022-08-26 10:54:38 +00:00
|
|
|
|
|
|
|
time.sleep(60)
|
|
|
|
|
2023-02-15 09:12:41 +00:00
|
|
|
files = [f for f in os.listdir(self.tmp_dir) if f.startswith('test-periodic')]
|
|
|
|
assert len(files) > 0 and any(f.endswith('summary.dfs') for f in files)
|