Files
lighthouse/beacon_node/http_metrics/tests/tests.rs
Mac L 8c2a909061 Bump warp and begin axum migration (#9001)
- Bump `warp` to 0.4. This unifies `warp` and `axum` onto the same `http`, `hyper`, `h2`, `rustls`, etc versions.
- Create `axum_utils` which contain common functions and types
- Begins migration of all HTTP API servers from warp to axum


Co-Authored-By: Mac L <mjladson@pm.me>
2026-06-25 14:19:29 +00:00

57 lines
1.7 KiB
Rust

use beacon_chain::test_utils::EphemeralHarnessType;
use http_metrics::Config;
use logging::create_test_tracing_subscriber;
use reqwest::StatusCode;
use reqwest::header::HeaderValue;
use std::net::{IpAddr, Ipv4Addr};
use std::sync::Arc;
use tokio::sync::oneshot;
use types::MainnetEthSpec;
type Context = http_metrics::Context<EphemeralHarnessType<MainnetEthSpec>>;
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
async fn returns_200_ok() {
create_test_tracing_subscriber();
async {
let context = Arc::new(Context {
config: Config {
enabled: true,
listen_addr: IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
listen_port: 0,
allow_origin: None,
allocator_metrics_enabled: true,
},
chain: None,
db_path: None,
freezer_db_path: None,
gossipsub_registry: None,
});
let ctx = context.clone();
let (_shutdown_tx, shutdown_rx) = oneshot::channel::<()>();
let server_shutdown = async {
// It's not really interesting why this triggered, just that it happened.
let _ = shutdown_rx.await;
};
let (listening_socket, server) = http_metrics::serve(ctx, server_shutdown).await.unwrap();
tokio::spawn(server);
let url = format!(
"http://{}:{}/metrics",
listening_socket.ip(),
listening_socket.port()
);
let response = reqwest::get(&url).await.unwrap();
assert_eq!(response.status(), StatusCode::OK);
assert_eq!(
response.headers().get("Content-Type").unwrap(),
&HeaderValue::from_str("text/plain").unwrap()
);
}
.await
}