Files

43 lines
1.3 KiB
Rust

//! Throughput of the request pipeline (in-process, no sockets).
//!
//! Authenticated routes are intentionally rate limited to 60 req/min per
//! device, so throughput is measured on the public health endpoint.
//! Run with: cargo test -p server --release --test load -- --ignored --nocapture
use std::time::Instant;
use axum::body::Body;
use axum::http::Request;
use http_body_util::BodyExt;
use tower::ServiceExt;
use server::{router, test_state};
#[tokio::test]
#[ignore = "throughput measurement, run manually"]
async fn health_throughput() {
let state = test_state().await;
let app = router(state);
let requests = 5_000;
let started = Instant::now();
for _ in 0..requests {
let req = Request::builder()
.uri("/v1/health")
.body(Body::empty())
.unwrap();
let resp = app.clone().oneshot(req).await.expect("request");
assert_eq!(resp.status(), axum::http::StatusCode::OK);
let _ = resp.into_body().collect().await.expect("body");
}
let elapsed = started.elapsed().as_secs_f64();
println!(
"requests={requests} elapsed={elapsed:.2}s throughput={:.0} req/s (single task, in-process)",
requests as f64 / elapsed
);
assert!(
requests as f64 / elapsed > 200.0,
"expected more than 200 req/s"
);
}