Compare commits
2
Commits
4dfaf28082
...
3f7f38cadd
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
3f7f38cadd | ||
|
|
1110f77112 |
@@ -53,8 +53,8 @@ def main():
|
||||
# --- чужой чат ---
|
||||
c.call('GET', path, 404, actor=eve)
|
||||
c.call('GET', path + '/messages', 404, actor=eve)
|
||||
c.call('POST', path + '/messages', 404, actor=eve, body={'text': 'чужое'})
|
||||
|
||||
c.call('POST', path + '/messages', 404, actor=eve, body={'text': 'чужое'},
|
||||
headers={'Idempotency-Key': uuid.uuid4().hex})
|
||||
# --- чат без создателя в member_ids ---
|
||||
c.call('POST', '/api/v1/chats', 400, actor=alice,
|
||||
body={'title': 'Без меня', 'member_ids': [bob['id']]})
|
||||
|
||||
@@ -60,19 +60,22 @@ def main():
|
||||
local = Client(args.base_url, args.ca_file, timeout=10)
|
||||
barrier2.wait()
|
||||
try:
|
||||
local.call('POST', '/api/v1/users', 201, body=body)
|
||||
return 'ok'
|
||||
except Failure:
|
||||
return 'conflict'
|
||||
r = local.call('POST', '/api/v1/users', (201, 409), body=body)
|
||||
return 'ok' if r['status'] == 201 else 'conflict'
|
||||
except Failure as e:
|
||||
return 'error: ' + str(e)
|
||||
|
||||
with ThreadPoolExecutor(max_workers=workers) as pool:
|
||||
results = list(pool.map(register, range(workers)))
|
||||
|
||||
ok_count = results.count('ok')
|
||||
conflict_count = results.count('conflict')
|
||||
error_count = sum(1 for r in results if r.startswith('error:'))
|
||||
check(ok_count == 1, 'ожидалась ровно одна успешная регистрация, получено %d' % ok_count)
|
||||
check(conflict_count == workers - 1,
|
||||
'ожидалось %d конфликтов, получено %d' % (workers - 1, conflict_count))
|
||||
check(error_count == 0,
|
||||
'неожиданные ошибки: %s' % [r for r in results if r.startswith('error:')])
|
||||
|
||||
print('PASS: конкурентность (100 сообщений, 1 победитель в гонке за username)')
|
||||
|
||||
|
||||
Reference in New Issue
Block a user