Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_cassandra.py
Show First 20 Lines • Show All 564 Lines • ▼ Show 20 Lines | def test_directory_add_atomic(self, swh_storage, sample_data, mocker, insert_algo): | ||||
directory = self._directory_with_entries(sample_data, BATCH_INSERT_MAX_SIZE) | directory = self._directory_with_entries(sample_data, BATCH_INSERT_MAX_SIZE) | ||||
entries = directory.entries | entries = directory.entries | ||||
directory = attr.evolve(directory, entries=entries + (CrashyEntry(),)) | directory = attr.evolve(directory, entries=entries + (CrashyEntry(),)) | ||||
with pytest.raises(TypeError): | with pytest.raises(TypeError): | ||||
swh_storage.directory_add([directory]) | swh_storage.directory_add([directory]) | ||||
# This should have written some of the entries to the database: | # Usually, this writes all entries but the crashy one in the database; | ||||
# let's check this. (If this assertion fails, then the test is useless; | |||||
# but it does not affect the actual functionality) | |||||
# However, because they are inserted simultaneously, the backend may crash | |||||
# before the last handful of entries; so we allow them to be missing | |||||
# without failing the test (which would make it flaky). | |||||
entry_rows = swh_storage._cql_runner.directory_entry_get([directory.id]) | entry_rows = swh_storage._cql_runner.directory_entry_get([directory.id]) | ||||
assert {row.name for row in entry_rows} == {entry.name for entry in entries} | assert ( | ||||
{entry.name for entry in entries[0:-100]} | |||||
<= {row.name for row in entry_rows} | |||||
<= {entry.name for entry in entries} | |||||
) | |||||
# BUT, because not all the entries were written, the directory should | # BUT, because not all the entries were written, the directory should | ||||
# be considered not written. | # be considered not written. | ||||
assert swh_storage.directory_missing([directory.id]) == [directory.id] | assert swh_storage.directory_missing([directory.id]) == [directory.id] | ||||
assert list(swh_storage.directory_ls(directory.id)) == [] | assert list(swh_storage.directory_ls(directory.id)) == [] | ||||
assert swh_storage.directory_get_entries(directory.id) is None | assert swh_storage.directory_get_entries(directory.id) is None | ||||
def test_directory_add_raw_manifest__different_entries__allow_overwrite( | def test_directory_add_raw_manifest__different_entries__allow_overwrite( | ||||
▲ Show 20 Lines • Show All 221 Lines • Show Last 20 Lines |