Quellcode durchsuchen

add extra test for the hashindex

Insert a few keys, delete some of them, check we still have
the values we expect, check the deleted ones aren't there.
Radu Ciorba vor 8 Jahren
Ursprung
Commit
8c2064cc5a
1 geänderte Dateien mit 25 neuen und 0 gelöschten Zeilen
  1. 25 0
      src/borg/testsuite/hashindex.py

+ 25 - 0
src/borg/testsuite/hashindex.py

@@ -125,6 +125,31 @@ class HashIndexTestCase(BaseTestCase):
         assert unique_chunks == 3
 
 
+class HashIndexExtraTestCase(BaseTestCase):
+    """These tests are separate because they should not become part of the selftest
+    """
+    def test_chunk_indexer(self):
+        # see _hashindex.c hash_sizes, we want to be close to the max fill rate
+        # because interesting errors happen there
+        max_key = int(65537 * 0.75) - 10
+        index = ChunkIndex(max_key)
+        deleted_keys = [
+            hashlib.sha256(H(k)).digest()
+            for k in range(-1, -(max_key//3), -1)]
+        keys = [hashlib.sha256(H(k)).digest() for k in range(max_key)]
+        for i, key in enumerate(keys):
+            index[key] = (i, i, i)
+        for i, key in enumerate(deleted_keys):
+            index[key] = (i, i, i)
+
+        for key in deleted_keys:
+            del index[key]
+        for i, key in enumerate(keys):
+            assert index[key] == (i, i, i)
+        for key in deleted_keys:
+            assert index.get(key) is None
+
+
 class HashIndexSizeTestCase(BaseTestCase):
     def test_size_on_disk(self):
         idx = ChunkIndex()