2020-10-19 05:58:39 +00:00
|
|
|
use beacon_chain::test_utils::EphemeralHarnessType;
|
2020-09-29 03:46:54 +00:00
|
|
|
use environment::null_logger;
|
|
|
|
use http_metrics::Config;
|
2023-02-28 02:20:50 +00:00
|
|
|
use reqwest::header::HeaderValue;
|
2020-09-29 03:46:54 +00:00
|
|
|
use reqwest::StatusCode;
|
2022-03-24 00:04:49 +00:00
|
|
|
use std::net::{IpAddr, Ipv4Addr};
|
2020-09-29 03:46:54 +00:00
|
|
|
use std::sync::Arc;
|
|
|
|
use tokio::sync::oneshot;
|
|
|
|
use types::MainnetEthSpec;
|
|
|
|
|
2020-10-19 05:58:39 +00:00
|
|
|
type Context = http_metrics::Context<EphemeralHarnessType<MainnetEthSpec>>;
|
2020-09-29 03:46:54 +00:00
|
|
|
|
2020-11-28 05:30:57 +00:00
|
|
|
#[tokio::test(flavor = "multi_thread", worker_threads = 2)]
|
2020-09-29 03:46:54 +00:00
|
|
|
async fn returns_200_ok() {
|
2020-11-28 05:30:57 +00:00
|
|
|
async {
|
|
|
|
let log = null_logger().unwrap();
|
2020-09-29 03:46:54 +00:00
|
|
|
|
2020-11-28 05:30:57 +00:00
|
|
|
let context = Arc::new(Context {
|
|
|
|
config: Config {
|
|
|
|
enabled: true,
|
2022-03-24 00:04:49 +00:00
|
|
|
listen_addr: IpAddr::V4(Ipv4Addr::new(127, 0, 0, 1)),
|
2020-11-28 05:30:57 +00:00
|
|
|
listen_port: 0,
|
|
|
|
allow_origin: None,
|
2021-05-28 05:59:45 +00:00
|
|
|
allocator_metrics_enabled: true,
|
2020-11-28 05:30:57 +00:00
|
|
|
},
|
|
|
|
chain: None,
|
|
|
|
db_path: None,
|
|
|
|
freezer_db_path: None,
|
2021-12-22 06:17:14 +00:00
|
|
|
gossipsub_registry: None,
|
2020-11-28 05:30:57 +00:00
|
|
|
log,
|
|
|
|
});
|
2020-09-29 03:46:54 +00:00
|
|
|
|
2020-11-28 05:30:57 +00:00
|
|
|
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).unwrap();
|
2020-09-29 03:46:54 +00:00
|
|
|
|
2020-11-28 05:30:57 +00:00
|
|
|
tokio::spawn(async { server.await });
|
2020-09-29 03:46:54 +00:00
|
|
|
|
2020-11-28 05:30:57 +00:00
|
|
|
let url = format!(
|
|
|
|
"http://{}:{}/metrics",
|
|
|
|
listening_socket.ip(),
|
|
|
|
listening_socket.port()
|
|
|
|
);
|
2020-09-29 03:46:54 +00:00
|
|
|
|
2023-02-28 02:20:50 +00:00
|
|
|
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()
|
|
|
|
);
|
2020-11-28 05:30:57 +00:00
|
|
|
}
|
|
|
|
.await
|
2020-09-29 03:46:54 +00:00
|
|
|
}
|