ЛР 2: мессенджер на PostgreSQL и сессии в Redis
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,26 @@
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from threading import Barrier
|
||||
from uuid import uuid4
|
||||
|
||||
from tests.client import Client
|
||||
|
||||
|
||||
def test_only_one_concurrent_registration_succeeds():
|
||||
username = 'race_' + uuid4().hex[:16]
|
||||
body = {
|
||||
'username': username,
|
||||
'display_name': 'Race user',
|
||||
'password': 'Race-password-' + uuid4().hex,
|
||||
}
|
||||
barrier = Barrier(8)
|
||||
|
||||
def register_once(_: int) -> int:
|
||||
client = Client()
|
||||
barrier.wait()
|
||||
return client.call('POST', '/api/v1/users', expected=[201, 409], body=body)['status']
|
||||
|
||||
with ThreadPoolExecutor(max_workers=8) as pool:
|
||||
statuses = list(pool.map(register_once, range(8)))
|
||||
|
||||
assert statuses.count(201) == 1
|
||||
assert statuses.count(409) == 7
|
||||
Reference in New Issue
Block a user