ЛР 4: S3-вложения и исследование согласованности — Майорова БВТ2301

This commit is contained in:
2026-10-27 13:17:07 +03:00
parent ec540a1a72
commit 96007f4c5a
71 changed files with 7246 additions and 41 deletions
+32
View File
@@ -0,0 +1,32 @@
"""A continuously trickling client still reaches the absolute upload deadline."""
import json
from pathlib import Path
import select
import socket
import sys
import time
import uuid
from urllib.parse import urlsplit
sys.path.insert(0, str(Path(__file__).resolve().parents[1] / 'tests'))
from client import Client
c = Client()
alice, bob, eve, chat = c.bootstrap()
target = urlsplit(c.base)
connection = socket.create_connection((target.hostname, target.port), timeout=3)
header = 'POST /api/v1/chats/' + chat['id'] + '/attachments?filename=slow_' + uuid.uuid4().hex + '.png HTTP/1.1\r\nHost: localhost\r\nAuthorization: Bearer ' + alice['token'] + '\r\nContent-Type: image/png\r\nContent-Length: 10485760\r\nConnection: close\r\n\r\n'
started = time.monotonic()
connection.sendall(header.encode())
response = b''
while time.monotonic() - started < 20:
if select.select([connection], [], [], .15)[0]:
response += connection.recv(4096)
if b'\r\n\r\n' in response:
break
connection.sendall(b'x')
connection.close()
elapsed = time.monotonic() - started
assert response.startswith(b'HTTP/1.1 400') or response.startswith(b'HTTP/1.0 400'), response[:100]
assert 14 <= elapsed < 19
assert b'x-instance-id:' in response.lower() and b'x-request-id:' in response.lower()
print(json.dumps({'trickle_seconds': round(elapsed, 3), 'http_status': 400, 'absolute_deadline_enforced': True}))