Projet

Général

Profil

0002-tests-adapt-to-concurrency-number-to-tests-60645.patch

Benjamin Dauvergne, 13 janvier 2022 23:08

Télécharger (2,51 ko)

Voir les différences:

Subject: [PATCH 2/2] tests: adapt to concurrency number to tests (#60645)

 tests/conftest.py          | 12 +++++++-----
 tests/test_concurrency.py  |  3 ++-
 tests/test_utils_models.py |  5 +++--
 3 files changed, 12 insertions(+), 8 deletions(-)
tests/conftest.py
270 270

  
271 271

  
272 272
@pytest.fixture
273
def concurrency(settings):
274
    """Select a level of concurrency based on the db. Currently only
275
    postgresql is supported.
276
    """
277
    return 100
273
def max_concurrency():
274
    return 30
275

  
276

  
277
@pytest.fixture
278
def typical_concurrency(settings):
279
    return 5
278 280

  
279 281

  
280 282
@pytest.fixture
tests/test_concurrency.py
23 23

  
24 24

  
25 25
@pytest.mark.slow
26
def test_attribute_value_uniqueness(transactional_db, simple_user, concurrency, pytestconfig):
26
def test_attribute_value_uniqueness(transactional_db, simple_user, max_concurrency, pytestconfig):
27
    concurrency = max_concurrency
27 28
    if pytestconfig.getoption('nomigrations'):
28 29
        pytest.skip('running migrations is required for this test')
29 30
    # disable default attributes
tests/test_utils_models.py
24 24
from authentic2.utils.models import safe_get_or_create
25 25

  
26 26

  
27
def test_safe_get_or_create(transactional_db, concurrency):
27
def test_safe_get_or_create(transactional_db, typical_concurrency):
28
    concurrency = typical_concurrency
28 29
    EMAIL = 'john.doe@example.net'
29 30
    barrier = threading.Barrier(concurrency)
30 31
    users = []
......
51 52
    assert len(users) == 1
52 53
    assert User.objects.count() == 1
53 54
    assert all(isinstance(exception, MultipleObjectsReturned) for exception in exceptions)
54
    assert len(exceptions) < (0.5 * concurrency)  # 50% of failure is 'ok-ish' with a lot of concurrency
55
    assert len(exceptions) < concurrency  # At least one is ok
55 56
    users[0].delete()
56
-