소스 검색

fix check_cache and test_check_cache

NewCache and AdHocCache do not have a persistent chunks index,
so both check_cache and test_check_cache are pointless.
Thomas Waldmann 1 년 전
부모
커밋
e3a0c4f375
2개의 변경된 파일10개의 추가작업 그리고 1개의 파일을 삭제
  1. 7 1
      src/borg/testsuite/archiver/__init__.py
  2. 3 0
      src/borg/testsuite/archiver/checks.py

+ 7 - 1
src/borg/testsuite/archiver/__init__.py

@@ -18,7 +18,7 @@ import pytest
 from ... import xattr, platform
 from ... import xattr, platform
 from ...archive import Archive
 from ...archive import Archive
 from ...archiver import Archiver, PURE_PYTHON_MSGPACK_WARNING
 from ...archiver import Archiver, PURE_PYTHON_MSGPACK_WARNING
-from ...cache import Cache
+from ...cache import Cache, LocalCache
 from ...constants import *  # NOQA
 from ...constants import *  # NOQA
 from ...helpers import Location, umount
 from ...helpers import Location, umount
 from ...helpers import EXIT_SUCCESS
 from ...helpers import EXIT_SUCCESS
@@ -356,9 +356,15 @@ def check_cache(archiver):
         manifest = Manifest.load(repository, Manifest.NO_OPERATION_CHECK)
         manifest = Manifest.load(repository, Manifest.NO_OPERATION_CHECK)
         with Cache(repository, manifest, sync=False) as cache:
         with Cache(repository, manifest, sync=False) as cache:
             original_chunks = cache.chunks
             original_chunks = cache.chunks
+            # the LocalCache implementation has an on-disk chunks cache,
+            # but NewCache and AdHocCache don't have persistent chunks cache.
+            persistent = isinstance(cache, LocalCache)
         Cache.destroy(repository)
         Cache.destroy(repository)
         with Cache(repository, manifest) as cache:
         with Cache(repository, manifest) as cache:
             correct_chunks = cache.chunks
             correct_chunks = cache.chunks
+    if not persistent:
+        # there is no point in doing the checks
+        return
     assert original_chunks is not correct_chunks
     assert original_chunks is not correct_chunks
     seen = set()
     seen = set()
     for id, (refcount, size) in correct_chunks.iteritems():
     for id, (refcount, size) in correct_chunks.iteritems():

+ 3 - 0
src/borg/testsuite/archiver/checks.py

@@ -317,6 +317,9 @@ def test_check_cache(archivers, request):
             cache.begin_txn()
             cache.begin_txn()
             cache.chunks.incref(list(cache.chunks.iteritems())[0][0])
             cache.chunks.incref(list(cache.chunks.iteritems())[0][0])
             cache.commit()
             cache.commit()
+            persistent = isinstance(cache, LocalCache)
+    if not persistent:
+        pytest.skip("check_cache is pointless if we do not have a persistent chunks cache")
     with pytest.raises(AssertionError):
     with pytest.raises(AssertionError):
         check_cache(archiver)
         check_cache(archiver)