forked from mtusi2026/mtusi2026lab6
Завершить трек 2: burn-rate alerts, повторные эксперименты и отчёт
This commit is contained in:
@@ -0,0 +1,38 @@
|
||||
"""SQL failure at result publication must be retry, followed by lease recovery."""
|
||||
import hashlib
|
||||
import json
|
||||
import time
|
||||
from common import *
|
||||
|
||||
|
||||
def main():
|
||||
c=Client(BASE);alice,bob,eve,chat=c.bootstrap()
|
||||
dc('stop','-t','2','worker')
|
||||
response=c.call('POST','/api/v1/chats/'+chat['id']+'/attachments?filename=db-retry.png',202,
|
||||
actor=alice,raw=(ROOT/'tests/fixtures/sample.png').read_bytes(),headers={'Content-Type':'image/png'},schema='Attachment')
|
||||
tid=response['headers']['X-Trace-Id'];att=response['json']
|
||||
lock=DBLock();lock.start('attachment_variants')
|
||||
before=snapshot();start=time.time()
|
||||
try:
|
||||
dc('start','worker')
|
||||
deadline=time.monotonic()+30
|
||||
while time.monotonic()<deadline:
|
||||
logs=query('loki','/loki/api/v1/query_range',query='{service_name="messenger-worker"} |= "'+tid+'" |= "retry"',limit=20)
|
||||
if logs['data']['result']:break
|
||||
time.sleep(1)
|
||||
check(bool(logs['data']['result']),'SQL result failure not recorded as retry')
|
||||
finally:lock.stop()
|
||||
ready=c.wait_ready(alice,att,wait_seconds=120)
|
||||
for variant in ['original','thumbnail','crop','optimized']:
|
||||
download=c.call('GET','/api/v1/attachments/'+att['id']+'/content?variant='+variant,actor=alice)
|
||||
expected=ready if variant=='original' else next(v for v in ready['variants'] if v['name']==variant)
|
||||
check(hashlib.sha256(download['bytes']).hexdigest()==expected['sha256'],'bytes changed during SQL retry')
|
||||
time.sleep(3)
|
||||
doc,spans=trace_wait(tid)
|
||||
check(any(s['status'].get('code')=='STATUS_CODE_ERROR' for s in spans if s['kind']=='SPAN_KIND_CONSUMER'),'consumer error missing')
|
||||
save('worker-db-failure.json',{'trace_id':tid,'attachment_id':att['id'],'before':before,'after':snapshot(),
|
||||
'duration':time.time()-start,'retry_logs':logs,'spans':spans,'result':'ready; all four checksums match'})
|
||||
print('PASS: result publication SQL failure recorded as retry, lease recovery, immutable bytes')
|
||||
|
||||
|
||||
if __name__=='__main__':main()
|
||||
Reference in New Issue
Block a user