Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_retry.py
Show First 20 Lines • Show All 41 Lines • ▼ Show 20 Lines | def swh_storage_backend_config(): | ||||
} | } | ||||
def test_retrying_proxy_storage_content_add(swh_storage, sample_data): | def test_retrying_proxy_storage_content_add(swh_storage, sample_data): | ||||
"""Standard content_add works as before | """Standard content_add works as before | ||||
""" | """ | ||||
sample_content = sample_data.content | sample_content = sample_data.content | ||||
content = next(swh_storage.content_get([sample_content.sha1])) | content = swh_storage.content_get_data(sample_content.sha1) | ||||
ardumont: It doesn't get more confusing than that.
Here the author most probably meant… | |||||
assert not content | assert content is None | ||||
s = swh_storage.content_add([sample_content]) | s = swh_storage.content_add([sample_content]) | ||||
assert s == { | assert s == { | ||||
"content:add": 1, | "content:add": 1, | ||||
"content:add:bytes": sample_content.length, | "content:add:bytes": sample_content.length, | ||||
} | } | ||||
content = next(swh_storage.content_get([sample_content.sha1])) | content = swh_storage.content_get_data(sample_content.sha1) | ||||
assert content["sha1"] == sample_content.sha1 | assert content == sample_content.data | ||||
def test_retrying_proxy_storage_content_add_with_retry( | def test_retrying_proxy_storage_content_add_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 | ||||
""" | """ | ||||
mock_memory = mocker.patch("swh.storage.in_memory.InMemoryStorage.content_add") | mock_memory = mocker.patch("swh.storage.in_memory.InMemoryStorage.content_add") | ||||
mock_memory.side_effect = [ | 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 already inserted"), | psycopg2.IntegrityError("content already inserted"), | ||||
# ok then! | # ok then! | ||||
{"content:add": 1}, | {"content:add": 1}, | ||||
] | ] | ||||
sample_content = sample_data.content | sample_content = sample_data.content | ||||
content = next(swh_storage.content_get([sample_content.sha1])) | content = swh_storage.content_get_data(sample_content.sha1) | ||||
assert not content | assert content is None | ||||
s = swh_storage.content_add([sample_content]) | s = swh_storage.content_add([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_failure( | def test_retrying_proxy_swh_storage_content_add_failure( | ||||
swh_storage, sample_data, mocker | swh_storage, sample_data, mocker | ||||
): | ): | ||||
"""Unfiltered errors are raising without retry | """Unfiltered errors are raising without retry | ||||
""" | """ | ||||
mock_memory = mocker.patch("swh.storage.in_memory.InMemoryStorage.content_add") | mock_memory = mocker.patch("swh.storage.in_memory.InMemoryStorage.content_add") | ||||
mock_memory.side_effect = StorageArgumentException("Refuse to add content always!") | mock_memory.side_effect = StorageArgumentException("Refuse to add content always!") | ||||
sample_content = sample_data.content | sample_content = sample_data.content | ||||
content = next(swh_storage.content_get([sample_content.sha1])) | content = swh_storage.content_get_data(sample_content.sha1) | ||||
assert not content | assert content is None | ||||
with pytest.raises(StorageArgumentException, match="Refuse to add"): | with pytest.raises(StorageArgumentException, match="Refuse to add"): | ||||
swh_storage.content_add([sample_content]) | swh_storage.content_add([sample_content]) | ||||
assert mock_memory.call_count == 1 | assert mock_memory.call_count == 1 | ||||
def test_retrying_proxy_storage_content_add_metadata(swh_storage, sample_data): | def test_retrying_proxy_storage_content_add_metadata(swh_storage, sample_data): | ||||
▲ Show 20 Lines • Show All 712 Lines • Show Last 20 Lines |
It doesn't get more confusing than that.
Here the author most probably meant content_get_metadata and not this one.
I won't change it now though.
Later when i'm done renaming those endpoint appropriately.