Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_postgresql.py
Show First 20 Lines • Show All 42 Lines • ▼ Show 20 Lines | def test_content_add_objstorage_exception(self, swh_storage, sample_data): | ||||
missing = list(swh_storage.content_missing([content.hashes()])) | missing = list(swh_storage.content_missing([content.hashes()])) | ||||
assert missing == [content.sha1] | assert missing == [content.sha1] | ||||
@pytest.mark.db | @pytest.mark.db | ||||
class TestStorageRaceConditions: | class TestStorageRaceConditions: | ||||
@pytest.mark.xfail | @pytest.mark.xfail | ||||
def test_content_add_race(self, swh_storage, sample_data): | def test_content_add_race(self, swh_storage, sample_data): | ||||
content = sample_data.content | content = attr.evolve(sample_data.content, ctime=now()) | ||||
results = queue.Queue() | results = queue.Queue() | ||||
def thread(): | def thread(): | ||||
try: | try: | ||||
with db_transaction(swh_storage) as (db, cur): | with db_transaction(swh_storage) as (db, cur): | ||||
ret = swh_storage.content_add([content], db=db, cur=cur) | ret = swh_storage._content_add_metadata(db, cur, [content]) | ||||
results.put((threading.get_ident(), "data", ret)) | results.put((threading.get_ident(), "data", ret)) | ||||
except Exception as e: | except Exception as e: | ||||
results.put((threading.get_ident(), "exc", e)) | results.put((threading.get_ident(), "exc", e)) | ||||
t1 = threading.Thread(target=thread) | t1 = threading.Thread(target=thread) | ||||
t2 = threading.Thread(target=thread) | t2 = threading.Thread(target=thread) | ||||
t1.start() | t1.start() | ||||
# this avoids the race condition | # this avoids the race condition | ||||
▲ Show 20 Lines • Show All 209 Lines • Show Last 20 Lines |