test(backup): add tests for cache reloads
continuous-integration/drone/push Build is failing Details

pull/94/head
Houkime 2024-02-12 21:23:01 +00:00 committed by Inex Code
parent bc0602bfcb
commit 4757bedc4e
2 changed files with 32 additions and 3 deletions

View File

@ -567,8 +567,7 @@ class Backups:
@staticmethod @staticmethod
def forget_snapshot(snapshot: Snapshot) -> None: def forget_snapshot(snapshot: Snapshot) -> None:
"""Deletes a snapshot from the repo and from cache""" """Deletes a snapshot from the repo and from cache"""
Backups.provider().backupper.forget_snapshot(snapshot.id) Backups.forget_snapshots([snapshot])
Storage.delete_cached_snapshot(snapshot)
@staticmethod @staticmethod
def forget_all_snapshots(): def forget_all_snapshots():

View File

@ -472,7 +472,8 @@ def test_snapshots_caching(backups, dummy_service):
cached_snapshots = Storage.get_cached_snapshots() cached_snapshots = Storage.get_cached_snapshots()
assert len(cached_snapshots) == 1 assert len(cached_snapshots) == 1
Storage.delete_cached_snapshot(cached_snapshots[0]) snap_to_uncache = cached_snapshots[0]
Storage.delete_cached_snapshot(snap_to_uncache)
cached_snapshots = Storage.get_cached_snapshots() cached_snapshots = Storage.get_cached_snapshots()
assert len(cached_snapshots) == 0 assert len(cached_snapshots) == 0
@ -484,6 +485,35 @@ def test_snapshots_caching(backups, dummy_service):
assert len(cached_snapshots) == 0 assert len(cached_snapshots) == 0
# Storage
def test_snapshot_cache_autoreloads(backups, dummy_service):
Backups.back_up(dummy_service)
cached_snapshots = Storage.get_cached_snapshots()
assert len(cached_snapshots) == 1
snap_to_uncache = cached_snapshots[0]
Storage.delete_cached_snapshot(snap_to_uncache)
cached_snapshots = Storage.get_cached_snapshots()
assert len(cached_snapshots) == 0
# When we create a snapshot we do reload cache
Backups.back_up(dummy_service)
cached_snapshots = Storage.get_cached_snapshots()
assert len(cached_snapshots) == 2
assert snap_to_uncache in cached_snapshots
Storage.delete_cached_snapshot(snap_to_uncache)
cached_snapshots = Storage.get_cached_snapshots()
assert len(cached_snapshots) == 1
# When we try to delete a snapshot we cannot find in cache, it is ok and we do reload cache
Backups.forget_snapshot(snap_to_uncache)
cached_snapshots = Storage.get_cached_snapshots()
assert len(cached_snapshots) == 1
assert snap_to_uncache not in cached_snapshots
def lowlevel_forget(snapshot_id): def lowlevel_forget(snapshot_id):
Backups.provider().backupper.forget_snapshot(snapshot_id) Backups.provider().backupper.forget_snapshot(snapshot_id)