fix(student-tests):lab4 distinguish 409 from 5xx in race test

This commit is contained in:
Голиков Maximillian Антон
2026-10-24 07:13:20 +03:00
parent 1110f77112
commit 3f7f38cadd
+7 -4
View File
@@ -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)')