mirror of
https://github.com/borgbackup/borg.git
synced 2024-12-25 17:27:31 +00:00
cleanup the test and add more checks
This commit is contained in:
parent
8c2064cc5a
commit
9f31dba7b5
1 changed files with 18 additions and 12 deletions
|
@ -126,29 +126,35 @@ def test_chunkindex_summarize(self):
|
||||||
|
|
||||||
|
|
||||||
class HashIndexExtraTestCase(BaseTestCase):
|
class HashIndexExtraTestCase(BaseTestCase):
|
||||||
"""These tests are separate because they should not become part of the selftest
|
"""These tests are separate because they should not become part of the selftest.
|
||||||
"""
|
"""
|
||||||
def test_chunk_indexer(self):
|
def test_chunk_indexer(self):
|
||||||
# see _hashindex.c hash_sizes, we want to be close to the max fill rate
|
# see _hashindex.c hash_sizes, we want to be close to the max. load
|
||||||
# because interesting errors happen there
|
# because interesting errors happen there.
|
||||||
max_key = int(65537 * 0.75) - 10
|
key_count = int(65537 * ChunkIndex.MAX_LOAD_FACTOR) - 10
|
||||||
index = ChunkIndex(max_key)
|
index = ChunkIndex(key_count)
|
||||||
deleted_keys = [
|
all_keys = [hashlib.sha256(H(k)).digest() for k in range(key_count)]
|
||||||
hashlib.sha256(H(k)).digest()
|
# we're gonna delete 1/3 of all_keys, so let's split them 2/3 and 1/3:
|
||||||
for k in range(-1, -(max_key//3), -1)]
|
keys, to_delete_keys = all_keys[0:(2*key_count//3)], all_keys[(2*key_count//3):]
|
||||||
keys = [hashlib.sha256(H(k)).digest() for k in range(max_key)]
|
|
||||||
for i, key in enumerate(keys):
|
for i, key in enumerate(keys):
|
||||||
index[key] = (i, i, i)
|
index[key] = (i, i, i)
|
||||||
for i, key in enumerate(deleted_keys):
|
for i, key in enumerate(to_delete_keys):
|
||||||
index[key] = (i, i, i)
|
index[key] = (i, i, i)
|
||||||
|
|
||||||
for key in deleted_keys:
|
for key in to_delete_keys:
|
||||||
del index[key]
|
del index[key]
|
||||||
for i, key in enumerate(keys):
|
for i, key in enumerate(keys):
|
||||||
assert index[key] == (i, i, i)
|
assert index[key] == (i, i, i)
|
||||||
for key in deleted_keys:
|
for key in to_delete_keys:
|
||||||
assert index.get(key) is None
|
assert index.get(key) is None
|
||||||
|
|
||||||
|
# now delete every key still in the index
|
||||||
|
for key in keys:
|
||||||
|
del index[key]
|
||||||
|
# the index should now be empty
|
||||||
|
assert list(index.iteritems()) == []
|
||||||
|
|
||||||
|
|
||||||
class HashIndexSizeTestCase(BaseTestCase):
|
class HashIndexSizeTestCase(BaseTestCase):
|
||||||
def test_size_on_disk(self):
|
def test_size_on_disk(self):
|
||||||
|
|
Loading…
Reference in a new issue