31 lines
1003 B
Python
31 lines
1003 B
Python
"""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',
|
|
201, 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()
|