From 8c2064cc5a63fc4f5b25eed30edb681b44b0fb08 Mon Sep 17 00:00:00 2001 From: Radu Ciorba Date: Mon, 20 Feb 2017 14:58:41 +0200 Subject: [PATCH] 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. --- src/borg/testsuite/hashindex.py | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/borg/testsuite/hashindex.py b/src/borg/testsuite/hashindex.py index 27747b423..4820c38c7 100644 --- a/src/borg/testsuite/hashindex.py +++ b/src/borg/testsuite/hashindex.py @@ -125,6 +125,31 @@ def test_chunkindex_summarize(self): 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()