Changeset View
Changeset View
Standalone View
Standalone View
swh/storage/tests/test_storage.py
Show First 20 Lines • Show All 3,232 Lines • ▼ Show 20 Lines | def test_content_add_objstorage_exception(self, swh_storage): | ||||
assert e.value.args == ('mocked broken objstorage',) | assert e.value.args == ('mocked broken objstorage',) | ||||
missing = list(swh_storage.content_missing([data.cont])) | missing = list(swh_storage.content_missing([data.cont])) | ||||
assert missing == [data.cont['sha1']] | assert missing == [data.cont['sha1']] | ||||
@pytest.mark.db | @pytest.mark.db | ||||
class TestStorageRaceConditions: | class TestStorageRaceConditions: | ||||
@pytest.mark.xfail | |||||
def test_content_add_race(self, swh_storage): | def test_content_add_race(self, swh_storage): | ||||
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([data.cont], db=db, | ret = swh_storage.content_add([data.cont], db=db, | ||||
Show All 12 Lines | def test_content_add_race(self, swh_storage): | ||||
t1.join() | t1.join() | ||||
t2.join() | t2.join() | ||||
r1 = results.get(block=False) | r1 = results.get(block=False) | ||||
r2 = results.get(block=False) | r2 = results.get(block=False) | ||||
with pytest.raises(queue.Empty): | with pytest.raises(queue.Empty): | ||||
results.get(block=False) | results.get(block=False) | ||||
assert r1[0] != r2[0] | assert r1[0] != r2[0] # Ident is unique | ||||
assert r1[1] == 'data', 'Got exception %r in Thread%s' % (r1[2], r1[0]) | assert r1[1] != r2[1] # Don't have same result | ||||
assert r2[1] == 'data', 'Got exception %r in Thread%s' % (r2[2], r2[0]) | if r1[1] == 'data': | ||||
(r_data, r_error) = (r1, r2) | |||||
else: | |||||
(r_data, r_error) = (r2, r1) | |||||
assert r_data[1] == 'data' | |||||
assert r_error[1] == 'exc', 'Got no exception %r in Thread%s' % ( | |||||
r_error[2], r_error[0]) | |||||
assert isinstance(r_error[2], psycopg2.errors.SerializationFailure) | |||||
@pytest.mark.db | @pytest.mark.db | ||||
class TestPgStorage: | class TestPgStorage: | ||||
"""This class is dedicated for the rare case where the schema needs to | """This class is dedicated for the rare case where the schema needs to | ||||
be altered dynamically. | be altered dynamically. | ||||
Otherwise, the tests could be blocking when ran altogether. | Otherwise, the tests could be blocking when ran altogether. | ||||
▲ Show 20 Lines • Show All 136 Lines • Show Last 20 Lines |