Complete lab 7 TLS and secret management
Skeleton contracts / contracts (pull_request) Canceled after 0s
Skeleton contracts / contracts (pull_request) Canceled after 0s
This commit is contained in:
@@ -0,0 +1,41 @@
|
||||
"""Demonstrate durable handoff while the worker is stopped and redelivery safety."""
|
||||
import subprocess
|
||||
from client import Client, arguments, check, run
|
||||
|
||||
|
||||
def compose(*args):
|
||||
subprocess.run(['docker','compose',*args],check=True,stdout=subprocess.DEVNULL)
|
||||
|
||||
|
||||
def main():
|
||||
args=arguments('Durable async image processing acceptance flow')
|
||||
c=Client(args.base_url,args.ca_file,timeout=10)
|
||||
alice,bob,eve,chat=c.bootstrap()
|
||||
compose('stop','worker')
|
||||
try:
|
||||
att,original=c.attachment(alice,chat)
|
||||
check(att['status']=='queued','upload should be durably queued while worker is stopped')
|
||||
c.call('GET','/api/v1/attachments/'+att['id']+'/content',409,actor=bob)
|
||||
msg=c.message(alice,chat,'',attachments=[att['id']])['json']
|
||||
check(msg['attachment_ids']==[att['id']],'queued attachment could not be linked to message')
|
||||
compose('restart','broker','api1','api2')
|
||||
compose('up','-d','worker')
|
||||
ready=c.wait_ready(bob,att,wait_seconds=60)
|
||||
check(ready['status']=='ready' and len(ready['variants'])==1,'worker did not publish one ready thumbnail')
|
||||
original_read=c.call('GET','/api/v1/attachments/'+att['id']+'/content',actor=bob)
|
||||
check(original_read['bytes']==original,'original changed during async processing')
|
||||
thumb=ready['variants'][0]
|
||||
content=c.call('GET','/api/v1/attachments/'+att['id']+'/content?variant=thumbnail',actor=bob)
|
||||
check(content['bytes'] and len(content['bytes'])==thumb['size_bytes'],'thumbnail bytes do not match metadata')
|
||||
# Redeliver the exact logical job. The ready state and deterministic object
|
||||
# keys make this a no-op; it cannot create another variant.
|
||||
code="import psycopg,os; from app.worker import publish; c=psycopg.connect(os.environ['DATABASE_URL']); p=c.execute('SELECT payload FROM attachment_jobs WHERE attachment_id=%s',(\""+att['id']+"\",)).fetchone()[0]; publish(p); publish(p); c.close()"
|
||||
subprocess.run(['docker','compose','exec','-T','worker','python','-c',code],check=True,stdout=subprocess.DEVNULL)
|
||||
check(c.wait_ready(bob,att)['variants']==ready['variants'],'duplicate delivery changed ready result')
|
||||
print('PASS: stopped-worker upload returned 202, survived API/broker restart, and reached ready')
|
||||
print('PASS: original preserved; repeated job delivery produced one identical thumbnail')
|
||||
finally:
|
||||
compose('up','-d','worker')
|
||||
|
||||
if __name__=='__main__':
|
||||
run(main)
|
||||
Reference in New Issue
Block a user