Измеряйте загрузку до подтверждения приёма вложения
This commit is contained in:
@@ -217,7 +217,7 @@ def upload(client_module, client, actor, chat, content, checksum, barrier, index
|
||||
result['status'] = response.code
|
||||
result['instance_id'] = response.headers.get('X-Instance-Id')
|
||||
body = response.read(65537)
|
||||
if result['status'] != 201:
|
||||
if result['status'] != 202:
|
||||
result['error'] = 'http_error'
|
||||
elif len(body) > 65536:
|
||||
result['error'] = 'oversized_metadata'
|
||||
@@ -225,7 +225,7 @@ def upload(client_module, client, actor, chat, content, checksum, barrier, index
|
||||
attachment = json.loads(body)
|
||||
client_module.shape(attachment, 'Attachment')
|
||||
valid = (attachment['sha256'] == checksum and attachment['size_bytes'] == len(content)
|
||||
and attachment['status'] == 'ready' and attachment['owner_id'] == actor['id']
|
||||
and attachment['status'] == 'queued' and attachment['owner_id'] == actor['id']
|
||||
and attachment['chat_id'] == chat['id'])
|
||||
result['ok'] = valid
|
||||
result['attachment_id'] = attachment['id']
|
||||
@@ -239,6 +239,15 @@ def upload(client_module, client, actor, chat, content, checksum, barrier, index
|
||||
return result
|
||||
|
||||
|
||||
def verify_download(client, reader, attachment_id, content, mime):
|
||||
# Poll after the upload measurements so latency ends at the durable handoff.
|
||||
client.wait_ready(reader, {'id': attachment_id})
|
||||
response = client.call('GET', '/api/v1/attachments/' + attachment_id + '/content', actor=reader)
|
||||
body = response['bytes']
|
||||
return {'ok': body == content and response['headers'].get_content_type() == mime,
|
||||
'bytes': len(body), 'sha256': hashlib.sha256(body).hexdigest(), 'status': response['status']}
|
||||
|
||||
|
||||
def run_case(module, bootstrap_client, actor, reader, chat, stats, args, case):
|
||||
name, width, height, size, seed = case
|
||||
content = payload_for(case)
|
||||
@@ -273,11 +282,7 @@ def run_case(module, bootstrap_client, actor, reader, chat, stats, args, case):
|
||||
download = {'ok': False}
|
||||
if successes:
|
||||
try:
|
||||
response = bootstrap_client.call('GET', '/api/v1/attachments/' + successes[0]['attachment_id'] + '/content', actor=reader)
|
||||
downloaded = response['bytes']
|
||||
download = {'ok': downloaded == content and response['headers'].get_content_type() == 'image/png',
|
||||
'bytes': len(downloaded), 'sha256': hashlib.sha256(downloaded).hexdigest(),
|
||||
'status': response['status']}
|
||||
download = verify_download(bootstrap_client, reader, successes[0]['attachment_id'], content, 'image/png')
|
||||
except Exception as exc:
|
||||
download['error'] = type(exc).__name__
|
||||
distinct = len({r['attachment_id'] for r in successes})
|
||||
|
||||
Reference in New Issue
Block a user