Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_buffer.py
Show First 20 Lines • Show All 353 Lines • ▼ Show 20 Lines | def test_buffering_proxy_storage_revision_deduplicate(sample_data) -> None: | ||||
missing_revisions = storage.revision_missing([r.id for r in revisions]) | missing_revisions = storage.revision_missing([r.id for r in revisions]) | ||||
assert list(missing_revisions) == [] | assert list(missing_revisions) == [] | ||||
s = storage.flush() | s = storage.flush() | ||||
assert s == {} | assert s == {} | ||||
def test_buffering_proxy_storage_revision_parents_threshold(sample_data) -> None: | |||||
revisions = sample_data.revisions | |||||
n_parents = sum(len(r.parents) for r in revisions) | |||||
threshold = sum(len(r.parents) for r in revisions[:-2]) | |||||
# ensure the threshold is in the middle | |||||
assert 0 < threshold < n_parents | |||||
storage = get_storage_with_buffer_config( | |||||
min_batch_size={"revision_parents": threshold} | |||||
) | |||||
storage.storage = Mock(wraps=storage.storage) | |||||
for revision in revisions: | |||||
storage.revision_add([revision]) | |||||
storage.flush() | |||||
# We should have called the underlying revision_add at least twice, as | |||||
# we have hit the threshold for number of parents on revision n-2 | |||||
method_calls = Counter(c[0] for c in storage.storage.method_calls) | |||||
assert method_calls["revision_add"] >= 2 | |||||
def test_buffering_proxy_storage_release_threshold_not_hit(sample_data) -> None: | def test_buffering_proxy_storage_release_threshold_not_hit(sample_data) -> None: | ||||
releases = sample_data.releases | releases = sample_data.releases | ||||
threshold = 10 | threshold = 10 | ||||
assert len(releases) < threshold | assert len(releases) < threshold | ||||
storage = get_storage_with_buffer_config( | storage = get_storage_with_buffer_config( | ||||
min_batch_size={"release": threshold,} # configuration set | min_batch_size={"release": threshold,} # configuration set | ||||
) | ) | ||||
▲ Show 20 Lines • Show All 287 Lines • Show Last 20 Lines |