#!/usr/bin/env python3 """Concurrent actual HTTP uploads; run only against a disposable QA deployment.""" import argparse from concurrent.futures import ThreadPoolExecutor import json import os from pathlib import Path import time import httpx p=argparse.ArgumentParser();p.add_argument('file',type=Path);p.add_argument('--url',default='http://127.0.0.1:8000');p.add_argument('--count',type=int,default=8);a=p.parse_args() raw=a.file.read_bytes();key=os.environ['API_KEY'] def one(_): with httpx.Client(base_url=a.url,timeout=30) as client: response=client.post('/api/v1/schematics/render',files={'file':(a.file.name,raw)},headers={'X-API-Key':key}) assert response.status_code==202,response.text return response.json() with ThreadPoolExecutor(max_workers=a.count) as pool: jobs=list(pool.map(one,range(a.count))) assert len({job['id'] for job in jobs})==a.count with httpx.Client(base_url=a.url,timeout=30) as client: for job in jobs: deadline=time.monotonic()+90 while time.monotonic()