(
args: argparse.Namespace,
s3_client,
bucket: str,
object_key: str,
)
| 134 | |
| 135 | def run_server_upload_flow( |
| 136 | args: argparse.Namespace, |
| 137 | s3_client, |
| 138 | bucket: str, |
| 139 | object_key: str, |
| 140 | ) -> Dict[str, float]: |
| 141 | put_url, get_url = generate_presigned_pair(s3_client, bucket, object_key, args.presign_expires) |
| 142 | payload = build_sync_payload(args, presigned_url=put_url) |
| 143 | |
| 144 | t0 = time.perf_counter() |
| 145 | response = call_sync(args.url, payload, args.timeout_seconds, args.poll_interval_seconds) |
| 146 | t1 = time.perf_counter() |
| 147 | if response.status_code != 200: |
| 148 | raise RuntimeError(f"[server_upload] sync failed ({response.status_code}): {response.text}") |
| 149 | |
| 150 | content_type = response.headers.get("content-type", "") |
| 151 | if "application/json" not in content_type: |
| 152 | raise RuntimeError(f"[server_upload] expected JSON but got content-type={content_type!r}") |
| 153 | body = response.json() |
| 154 | if not body.get("uploaded_to_presigned_url"): |
| 155 | raise RuntimeError(f"[server_upload] upload flag is false, response={json.dumps(body, ensure_ascii=False)}") |
| 156 | |
| 157 | if args.verify_download: |
| 158 | check_resp = requests.get(get_url, timeout=args.download_timeout_seconds) |
| 159 | if check_resp.status_code != 200: |
| 160 | raise RuntimeError(f"[server_upload] download verify failed ({check_resp.status_code}): {check_resp.text}") |
| 161 | |
| 162 | return { |
| 163 | "sync_total_ms": (t1 - t0) * 1000.0, |
| 164 | } |
| 165 | |
| 166 | |
| 167 | def print_summary(label: str, values: List[float]) -> None: |
| 168 | print(f"{label}: avg={statistics.mean(values):.2f} ms, p50={percentile(values, 0.5):.2f} ms, p90={percentile(values, 0.9):.2f} ms, min={min(values):.2f} ms, max={max(values):.2f} ms") |
no test coverage detected