forked from mtusi2026/mtusi2026lab4
ЛР 4 — вложения S3 и reconciler
This commit is contained in:
@@ -0,0 +1,23 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Concurrent duplicate POSTs through LB; assert one stable message result."""
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
import uuid
|
||||
from client import Client, arguments, check, run
|
||||
|
||||
def main():
|
||||
args=arguments('Parallel retry test through the shared load balancer')
|
||||
base=Client(args.base_url,args.ca_file,timeout=10)
|
||||
alice,bob,eve,chat=base.bootstrap(); key='race:'+uuid.uuid4().hex
|
||||
body={'text':'Параллельная отправка'}
|
||||
def send(_):
|
||||
c=Client(args.base_url,args.ca_file,timeout=10)
|
||||
return c.call('POST',f"/api/v1/chats/{chat['id']}/messages",201,actor=alice,body=body,headers={'Idempotency-Key':key},schema='Message')
|
||||
with ThreadPoolExecutor(max_workers=16) as pool: replies=list(pool.map(send,range(32)))
|
||||
ids={r['json']['id'] for r in replies}; instances={r['headers']['X-Instance-Id'] for r in replies}
|
||||
check(len(ids)==1,'concurrent retries created more than one message')
|
||||
check(len(instances)>=2,'test did not observe requests served by two API replicas')
|
||||
history=base.call('GET',f"/api/v1/chats/{chat['id']}/messages?limit=100",actor=bob,schema='MessagePage')['json']['items']
|
||||
check(sum(m['id'] in ids for m in history)==1,'message is not visible exactly once through LB')
|
||||
print(f'PASS: 32 concurrent retries, one message, {len(instances)} API instances observed')
|
||||
|
||||
if __name__=='__main__': run(main)
|
||||
Reference in New Issue
Block a user