Browse Source

fix test_cache_chunks

- skip test_cache_chunks if there is no persistent chunks cache file
- init self.chunks for AdHocCache
- remove warning output from AdHocCache.__init__, it gets mixed with JSON output and fails the JSON decoder.
Thomas Waldmann 10 months ago
parent
commit
c7249583e7

+ 3 - 2
src/borg/cache.py

@@ -428,6 +428,9 @@ Total chunks: {0.total_chunks}
     def stats(self):
         from .archive import Archive
 
+        if isinstance(self, AdHocCache) and getattr(self, "chunks", None) is None:
+            self.chunks = self._load_chunks_from_repo()  # AdHocCache usually only has .chunks after begin_txn.
+
         # XXX: this should really be moved down to `hashindex.pyx`
         total_size, unique_size, total_unique_chunks, total_chunks = self.chunks.summarize()
         # since borg 1.2 we have new archive metadata telling the total size per archive,
@@ -1340,8 +1343,6 @@ Chunk index:    {0.total_unique_chunks:20d}             unknown"""
         self.security_manager = SecurityManager(self.repository)
         self.security_manager.assert_secure(manifest, self.key, lock_wait=lock_wait)
 
-        logger.warning("Note: --no-cache-sync is an experimental feature.")
-
     # Public API
 
     def __enter__(self):

+ 3 - 4
src/borg/testsuite/archiver/corruption.py

@@ -53,11 +53,10 @@ def test_cache_chunks(archiver):
 
     create_src_archive(archiver, "test")
     chunks_path = os.path.join(archiver.cache_path, "chunks")
-    chunks_before_corruption = set(ChunkIndex(path=chunks_path).iteritems())
+    if not os.path.exists(chunks_path):
+        pytest.skip("no persistent chunks index for this kind of Cache implementation")
 
-    chunks_index = os.path.join(archiver.cache_path, "chunks")
-    if not os.path.exists(chunks_index):
-        pytest.skip("Only works with LocalCache.")
+    chunks_before_corruption = set(ChunkIndex(path=chunks_path).iteritems())
 
     corrupt(chunks_path)
 

+ 2 - 2
src/borg/testsuite/archiver/create_cmd.py

@@ -546,8 +546,8 @@ def test_create_no_cache_sync_adhoc(archivers, request):  # TODO: add test for N
     cmd(archiver, "rcreate", RK_ENCRYPTION)
     cmd(archiver, "rdelete", "--cache-only")
     create_json = json.loads(
-        cmd(archiver, "create", "--no-cache-sync", "--prefer-adhoc-cache", "--json", "--error", "test", "input")
-    )  # ignore experimental warning
+        cmd(archiver, "create", "--no-cache-sync", "--prefer-adhoc-cache", "--json", "test", "input")
+    )
     info_json = json.loads(cmd(archiver, "info", "-a", "test", "--json"))
     create_stats = create_json["cache"]["stats"]
     info_stats = info_json["cache"]["stats"]