#![allow(clippy::unwrap_used)]
mod common;
use bytes::Bytes;
use http_body_util::{BodyExt, Full};
use hyper::{Method, Request};
use hyper_util::client::legacy::Client;
use hyper_util::rt::TokioExecutor;
use common::{build_handler, payload, serve, start_upstream};
use osproxy_server::tenancy::PlacementMode;
const REQUESTS: usize = 200;
async fn drive(size: usize) {
let upstream = start_upstream().await;
let proxy = serve(build_handler(&upstream, Some(PlacementMode::SharedIndex))).await;
let body = payload(size);
let client: Client<_, Full<Bytes>> = Client::builder(TokioExecutor::new()).build_http();
let uri: hyper::Uri = format!("http://{proxy}/orders/_doc").parse().unwrap();
for _ in 0..REQUESTS {
let req = Request::builder()
.method(Method::POST)
.uri(uri.clone())
.header("content-type", "application/json")
.body(Full::new(body.clone()))
.unwrap();
let resp = client.request(req).await.unwrap();
assert!(resp.status().is_success());
let _ = resp.into_body().collect().await;
}
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
#[ignore = "profiling target; run under callgrind, see module docs"]
async fn profile_64k_single_connection() {
drive(65536).await;
}
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
#[ignore = "profiling target; run under callgrind, see module docs"]
async fn profile_256b_single_connection() {
drive(256).await;
}