Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_retry.py
Show First 20 Lines • Show All 111 Lines • ▼ Show 20 Lines | |||||
def test_retrying_proxy_storage_content_add_metadata(swh_storage, sample_data): | def test_retrying_proxy_storage_content_add_metadata(swh_storage, sample_data): | ||||
"""Standard content_add_metadata works as before | """Standard content_add_metadata works as before | ||||
""" | """ | ||||
sample_content = sample_data.content | sample_content = sample_data.content | ||||
content = attr.evolve(sample_content, data=None) | content = attr.evolve(sample_content, data=None) | ||||
pk = content.sha1 | pk = content.sha1 | ||||
content_metadata = swh_storage.content_get_metadata([pk]) | content_metadata = swh_storage.content_get([pk]) | ||||
assert not content_metadata[pk] | assert content_metadata == [None] | ||||
s = swh_storage.content_add_metadata([content]) | s = swh_storage.content_add_metadata([content]) | ||||
assert s == { | assert s == { | ||||
"content:add": 1, | "content:add": 1, | ||||
} | } | ||||
content_metadata = swh_storage.content_get_metadata([pk]) | content_metadata = swh_storage.content_get([pk]) | ||||
assert len(content_metadata[pk]) == 1 | assert len(content_metadata) == 1 | ||||
assert content_metadata[pk][0]["sha1"] == pk | assert content_metadata[0].sha1 == pk | ||||
def test_retrying_proxy_storage_content_add_metadata_with_retry( | def test_retrying_proxy_storage_content_add_metadata_with_retry( | ||||
monkeypatch_sleep, swh_storage, sample_data, mocker, fake_hash_collision | monkeypatch_sleep, swh_storage, sample_data, mocker, fake_hash_collision | ||||
): | ): | ||||
"""Multiple retries for hash collision and psycopg2 error but finally ok | """Multiple retries for hash collision and psycopg2 error but finally ok | ||||
""" | """ | ||||
Show All 31 Lines | ): | ||||
) | ) | ||||
mock_memory.side_effect = StorageArgumentException( | mock_memory.side_effect = StorageArgumentException( | ||||
"Refuse to add content_metadata!" | "Refuse to add content_metadata!" | ||||
) | ) | ||||
sample_content = sample_data.content | sample_content = sample_data.content | ||||
content = attr.evolve(sample_content, data=None) | content = attr.evolve(sample_content, data=None) | ||||
pk = content.sha1 | |||||
content_metadata = swh_storage.content_get_metadata([pk]) | |||||
assert not content_metadata[pk] | |||||
with pytest.raises(StorageArgumentException, match="Refuse to add"): | with pytest.raises(StorageArgumentException, match="Refuse to add"): | ||||
swh_storage.content_add_metadata([content]) | swh_storage.content_add_metadata([content]) | ||||
assert mock_memory.call_count == 1 | assert mock_memory.call_count == 1 | ||||
def test_retrying_proxy_storage_skipped_content_add(swh_storage, sample_data): | def test_retrying_proxy_storage_skipped_content_add(swh_storage, sample_data): | ||||
"""Standard skipped_content_add works as before | """Standard skipped_content_add works as before | ||||
▲ Show 20 Lines • Show All 635 Lines • Show Last 20 Lines |