Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_retry.py
Show First 20 Lines • Show All 122 Lines • ▼ Show 20 Lines | ): | ||||
assert mock_memory.call_count == 1 | assert mock_memory.call_count == 1 | ||||
def test_retrying_proxy_storage_content_add_metadata(swh_storage, sample_data_model): | def test_retrying_proxy_storage_content_add_metadata(swh_storage, sample_data_model): | ||||
"""Standard content_add_metadata works as before | """Standard content_add_metadata works as before | ||||
""" | """ | ||||
sample_content = sample_data_model["content_metadata"][0] | sample_content = sample_data_model["content_no_data"][0] | ||||
pk = sample_content.sha1 | pk = sample_content.sha1 | ||||
content_metadata = swh_storage.content_get_metadata([pk]) | content_metadata = swh_storage.content_get_metadata([pk]) | ||||
assert not content_metadata[pk] | assert not content_metadata[pk] | ||||
s = swh_storage.content_add_metadata([sample_content]) | s = swh_storage.content_add_metadata([sample_content]) | ||||
assert s == { | assert s == { | ||||
"content:add": 1, | "content:add": 1, | ||||
Show All 17 Lines | mock_memory.side_effect = [ | ||||
# first try goes ko | # first try goes ko | ||||
fake_hash_collision, | fake_hash_collision, | ||||
# second try goes ko | # second try goes ko | ||||
psycopg2.IntegrityError("content_metadata already inserted"), | psycopg2.IntegrityError("content_metadata already inserted"), | ||||
# ok then! | # ok then! | ||||
{"content:add": 1}, | {"content:add": 1}, | ||||
] | ] | ||||
sample_content = sample_data_model["content_metadata"][0] | sample_content = sample_data_model["content_no_data"][0] | ||||
s = swh_storage.content_add_metadata([sample_content]) | s = swh_storage.content_add_metadata([sample_content]) | ||||
assert s == {"content:add": 1} | assert s == {"content:add": 1} | ||||
mock_memory.assert_has_calls( | mock_memory.assert_has_calls( | ||||
[call([sample_content]), call([sample_content]), call([sample_content]),] | [call([sample_content]), call([sample_content]), call([sample_content]),] | ||||
) | ) | ||||
def test_retrying_proxy_swh_storage_content_add_metadata_failure( | def test_retrying_proxy_swh_storage_content_add_metadata_failure( | ||||
swh_storage, sample_data_model, mocker | swh_storage, sample_data_model, mocker | ||||
): | ): | ||||
"""Unfiltered errors are raising without retry | """Unfiltered errors are raising without retry | ||||
""" | """ | ||||
mock_memory = mocker.patch( | mock_memory = mocker.patch( | ||||
"swh.storage.in_memory.InMemoryStorage.content_add_metadata" | "swh.storage.in_memory.InMemoryStorage.content_add_metadata" | ||||
) | ) | ||||
mock_memory.side_effect = StorageArgumentException( | mock_memory.side_effect = StorageArgumentException( | ||||
"Refuse to add content_metadata!" | "Refuse to add content_metadata!" | ||||
) | ) | ||||
sample_content = sample_data_model["content_metadata"][0] | sample_content = sample_data_model["content_no_data"][0] | ||||
pk = sample_content.sha1 | pk = sample_content.sha1 | ||||
content_metadata = swh_storage.content_get_metadata([pk]) | content_metadata = swh_storage.content_get_metadata([pk]) | ||||
assert not content_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([sample_content]) | swh_storage.content_add_metadata([sample_content]) | ||||
▲ Show 20 Lines • Show All 672 Lines • Show Last 20 Lines |