浏览代码

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 8 年之前
父节点
当前提交
8c2064cc5a
共有 1 个文件被更改,包括 25 次插入0 次删除
  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()