Реализовать асинхронную обработку изображений

This commit is contained in:
Nik
2026-11-05 20:34:10 +03:00
parent 276dbdad8a
commit 35371114cd
28 changed files with 1968 additions and 45 deletions
+30
View File
@@ -0,0 +1,30 @@
"""Ten concurrent bounded uploads for a small local memory check."""
from concurrent.futures import ThreadPoolExecutor
from pathlib import Path
import sys
import uuid
sys.path.insert(0, str(Path(__file__).parents[1] / 'tests'))
from client import Client, check
def main():
client = Client('http://localhost:8080')
alice, _, _, chat = client.bootstrap()
data = (Path(__file__).parents[1] / 'tests/fixtures/sample.png').read_bytes()
def upload(number):
return client.call(
'POST', '/api/v1/chats/' + chat['id'] + '/attachments?filename=load-' + str(number) + '.png',
202, actor=alice, raw=data,
headers={'Content-Type': 'image/png'}, schema='Attachment',
)
with ThreadPoolExecutor(max_workers=10) as pool:
results = list(pool.map(upload, range(10)))
check(len(results) == 10, 'not all uploads completed')
print('PASS: 10 concurrent uploads, bytes per upload:', len(data))
if __name__ == '__main__':
main()