Skip to content

Commit c702c7b

Browse files
committed
Add testcase for read-write inconsistency
1 parent 28639ea commit c702c7b

File tree

2 files changed

+40
-1
lines changed

2 files changed

+40
-1
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,6 @@
1717
- id: filter-cascade-tests
1818
name: Tests for filter-cascade
1919
language: system
20-
entry: python3 -m pytest .
20+
entry: python3 -m pytest
2121
pass_filenames: false
2222
files: '.py$'

test_filtercascade.py filtercascade/test_filtercascade.py

+39
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import filtercascade
22
import hashlib
3+
import math
34
import unittest
45
from itertools import islice
56

@@ -321,6 +322,44 @@ def test_fc_standard_logic_disk_layout(self):
321322
self.assertEqual(h.data[4], ord("a")) # salt
322323
self.assertEqual(h.data[5], filtercascade.fileformats.HashAlgorithm.SHA256)
323324

325+
def test_fc_write_rewrite(self):
326+
_blocked = [
327+
("guid1@", "1.0"),
328+
("@guid2", "1.0"),
329+
("@guid2", "1.1"),
330+
("guid3@", "0.01b1"),
331+
]
332+
blocked = [f"{guid}:{version}" for guid, version in _blocked]
333+
_not_blocked = [
334+
("guid10@", "1.0"),
335+
("@guid20", "1.0"),
336+
("@guid20", "1.1"),
337+
("guid30@", "0.01b1"),
338+
("guid100@", "1.0"),
339+
("@guid200", "1.0"),
340+
("@guid200", "1.1"),
341+
("guid300@", "0.01b1"),
342+
]
343+
not_blocked = [f"{guid}:{version}" for guid, version in _not_blocked]
344+
345+
salt = b"sixteenbyteslong"
346+
fprs = [len(blocked) / (math.sqrt(2) * len(not_blocked)), 0.5]
347+
348+
cascade_out = filtercascade.FilterCascade.cascade_with_characteristics(
349+
capacity=int(len(blocked) * 1.1),
350+
error_rates=fprs,
351+
defaultHashAlg=filtercascade.fileformats.HashAlgorithm.SHA256,
352+
salt=salt,
353+
)
354+
cascade_out.initialize(include=blocked, exclude=not_blocked)
355+
cascade_out.verify(include=blocked, exclude=not_blocked)
356+
357+
f = MockFile()
358+
cascade_out.tofile(f)
359+
360+
cascade_in = filtercascade.FilterCascade.from_buf(f)
361+
cascade_in.verify(include=blocked, exclude=not_blocked)
362+
324363

325364
class TestFilterCascadeSalts(unittest.TestCase):
326365
def test_non_byte_salt(self):

0 commit comments

Comments
 (0)