Skip to content

Commit

Permalink
hashindex_pytest.py: factor out verify_hash_table
Browse files Browse the repository at this point in the history
  • Loading branch information
jdchristensen committed Feb 11, 2023
1 parent 6db21fa commit 133ffeb
Showing 1 changed file with 12 additions and 11 deletions.
23 changes: 12 additions & 11 deletions src/borg/testsuite/hashindex_pytest.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,15 @@
from ..hashindex import NSIndex


def verify_hash_table(kv, idx):
"""kv should be a python dictionary and idx an NSIndex. Check that idx
has the expected entries and the right number of entries.
"""
for k, v in kv.items():
assert k in idx and idx[k] == (v, v, v)
assert len(idx) == len(kv)


def make_hashtables(*, entries, loops):
idx = NSIndex()
kv = {}
Expand All @@ -23,11 +32,7 @@ def make_hashtables(*, entries, loops):
for k in delete_keys:
v = kv.pop(k)
assert idx.pop(k) == (v, v, v)
# check if remaining entries are as expected
for k, v in kv.items():
assert idx[k] == (v, v, v)
# check entry count
assert len(kv) == len(idx)
verify_hash_table(kv, idx)
return idx, kv


Expand All @@ -53,16 +58,12 @@ def test_hashindex_compact():
assert saved_space > 0
assert size_noncompact - size_compact == saved_space
# did we lose anything?
for k, v in kv.items():
assert k in idx and idx[k] == (v, v, v)
assert len(idx) == len(kv)
verify_hash_table(kv, idx)
# now expand the hashtable again. trigger a resize/rebuild by adding an entry.
k = b"x" * 32
idx[k] = (0, 0, 0)
kv[k] = 0
size_rebuilt = idx.size()
assert size_rebuilt > size_compact + 1
# did we lose anything?
for k, v in kv.items():
assert k in idx and idx[k] == (v, v, v)
assert len(idx) == len(kv)
verify_hash_table(kv, idx)

0 comments on commit 133ffeb

Please sign in to comment.