From 9697f5553436a625fba1fb7c2fe5542868998280 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 8 Feb 2023 01:53:30 +0100 Subject: [PATCH 1/2] add hashtable stress tests Using NSIndex (repo index) HashIndex, but they all are very similar. --- src/borg/testsuite/hashindex_stress.py | 32 ++++++++++++++++++++++++++ 1 file changed, 32 insertions(+) create mode 100644 src/borg/testsuite/hashindex_stress.py diff --git a/src/borg/testsuite/hashindex_stress.py b/src/borg/testsuite/hashindex_stress.py new file mode 100644 index 000000000..4b938368a --- /dev/null +++ b/src/borg/testsuite/hashindex_stress.py @@ -0,0 +1,32 @@ +import os +import random + +import pytest + +from ..hashindex import NSIndex + + +@pytest.mark.skipif("BORG_TESTS_SLOW" not in os.environ, reason="slow tests not enabled, use BORG_TESTS_SLOW=1") +def test_hashindex_stress(): + """checks if the hashtable behaves as expected""" + ENTRIES = 10000 + LOOPS = 100 + idx = NSIndex() + kv = {} + for i in range(LOOPS): + # put some entries + for j in range(ENTRIES): + k = random.randbytes(32) + v = random.randint(0, NSIndex.MAX_VALUE - 1) + idx[k] = (v, v, v) + kv[k] = v + # check and delete a random amount of entries + delete_keys = random.sample(list(kv), k=random.randint(0, len(kv))) + 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) From 3e336562385c34de4b6f4b26e2eb9f1ee48da169 Mon Sep 17 00:00:00 2001 From: Thomas Waldmann Date: Wed, 8 Feb 2023 02:10:38 +0100 Subject: [PATCH 2/2] add comment about how to provoke more collisions --- src/borg/testsuite/hashindex_stress.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/borg/testsuite/hashindex_stress.py b/src/borg/testsuite/hashindex_stress.py index 4b938368a..5cf8b75e1 100644 --- a/src/borg/testsuite/hashindex_stress.py +++ b/src/borg/testsuite/hashindex_stress.py @@ -8,9 +8,14 @@ from ..hashindex import NSIndex @pytest.mark.skipif("BORG_TESTS_SLOW" not in os.environ, reason="slow tests not enabled, use BORG_TESTS_SLOW=1") def test_hashindex_stress(): - """checks if the hashtable behaves as expected""" + """checks if the hashtable behaves as expected + + This can be used in _hashindex.c before running this test to provoke more collisions (don't forget to compile): + #define HASH_MAX_LOAD .99 + #define HASH_MAX_EFF_LOAD .999 + """ ENTRIES = 10000 - LOOPS = 100 + LOOPS = 1000 idx = NSIndex() kv = {} for i in range(LOOPS):