"""Interrupted client body must not produce metadata or S3 writes.""" from client import Client, check, run from track2 import sql, mc import socket,time def main(): c=Client(); a,b,e,chat=c.bootstrap() before=sql('select count(*) from attachments;') objects=mc('mc ls proof/messenger-attachments/') with socket.create_connection(('127.0.0.1',8080),timeout=5) as connection: headers=('POST /api/v1/chats/'+chat['id']+'/attachments?filename=partial.png HTTP/1.1\r\nHost: localhost\r\nAuthorization: Bearer '+a['token']+'\r\nContent-Type: image/png\r\nContent-Length: 1048576\r\n\r\n') connection.sendall(headers.encode()+b'partial') time.sleep(2) check(sql('select count(*) from attachments;')==before,'partial metadata committed') check(mc('mc ls proof/messenger-attachments/')==objects,'partial object stored') print('PASS interrupted upload: connection closed before full body; metadata and S3 object listing unchanged') if __name__ == '__main__': run(main)