diff --git a/crates/monitoring_endpoint/src/communication.rs b/crates/monitoring_endpoint/src/communication.rs index ff7122471d..cdfaa1da63 100644 --- a/crates/monitoring_endpoint/src/communication.rs +++ b/crates/monitoring_endpoint/src/communication.rs @@ -5,7 +5,7 @@ use crate::monitoring_endpoint::MonitoringEndpoint; pub type MonitoringEndpointServer = WrapperServer; pub fn create_monitoring_endpoint_server( - monitoring_endpont: MonitoringEndpoint, + monitoring_endpoint: MonitoringEndpoint, ) -> MonitoringEndpointServer { - create_empty_server(monitoring_endpont) + create_empty_server(monitoring_endpoint) } diff --git a/crates/monitoring_endpoint/src/config.rs b/crates/monitoring_endpoint/src/config.rs index 211fe25572..82384cf7da 100644 --- a/crates/monitoring_endpoint/src/config.rs +++ b/crates/monitoring_endpoint/src/config.rs @@ -1,4 +1,5 @@ use std::collections::BTreeMap; +use std::fmt::{Display, Formatter, Result}; use std::net::IpAddr; use papyrus_config::dumping::{ser_param, SerializeConfig}; @@ -37,9 +38,9 @@ impl SerializeConfig for MonitoringEndpointConfig { } } -impl std::fmt::Display for MonitoringEndpointConfig { +impl Display for MonitoringEndpointConfig { #[cfg_attr(coverage_nightly, coverage_attribute)] - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + fn fmt(&self, f: &mut Formatter<'_>) -> Result { write!(f, "{self:?}") } } diff --git a/crates/monitoring_endpoint/src/monitoring_endpoint.rs b/crates/monitoring_endpoint/src/monitoring_endpoint.rs index 31aa5a057b..3e3c9d087a 100644 --- a/crates/monitoring_endpoint/src/monitoring_endpoint.rs +++ b/crates/monitoring_endpoint/src/monitoring_endpoint.rs @@ -3,7 +3,8 @@ use std::net::SocketAddr; use axum::http::StatusCode; use axum::routing::get; -use axum::{async_trait, Router}; +use axum::{async_trait, Router, Server}; +use hyper::Error; use starknet_sequencer_infra::component_definitions::ComponentStarter; use starknet_sequencer_infra::errors::ComponentError; use tracing::{info, instrument}; @@ -33,14 +34,14 @@ impl MonitoringEndpoint { version = %self.version, ), level = "debug")] - pub async fn run(&self) -> Result<(), hyper::Error> { + pub async fn run(&self) -> Result<(), Error> { let MonitoringEndpointConfig { ip, port } = self.config; let endpoint_addr = SocketAddr::new(ip, port); let app = self.app(); info!("MonitoringEndpoint running using socket: {}", endpoint_addr); - axum::Server::bind(&endpoint_addr).serve(app.into_make_service()).await + Server::bind(&endpoint_addr).serve(app.into_make_service()).await } fn app(&self) -> Router { diff --git a/crates/monitoring_endpoint/src/monitoring_endpoint_test.rs b/crates/monitoring_endpoint/src/monitoring_endpoint_test.rs index 2d71a6ef5d..513d630d3c 100644 --- a/crates/monitoring_endpoint/src/monitoring_endpoint_test.rs +++ b/crates/monitoring_endpoint/src/monitoring_endpoint_test.rs @@ -1,10 +1,15 @@ use std::net::IpAddr; +use axum::body::Bytes; use axum::http::StatusCode; use axum::response::Response; -use axum::Router; +use axum::{Error, Router}; use http_body::combinators::UnsyncBoxBody; +use hyper::body::to_bytes; +use hyper::Client; use pretty_assertions::assert_eq; +use tokio::spawn; +use tokio::task::yield_now; use tower::ServiceExt; use super::MonitoringEndpointConfig; @@ -20,10 +25,7 @@ fn setup_monitoring_endpoint() -> MonitoringEndpoint { create_monitoring_endpoint(MonitoringEndpointConfig::default(), TEST_VERSION) } -async fn request_app( - app: Router, - method: &str, -) -> Response> { +async fn request_app(app: Router, method: &str) -> Response> { app.oneshot(build_request(&IpAddr::from([0, 0, 0, 0]), 0, method)).await.unwrap() } @@ -32,7 +34,7 @@ async fn test_node_version() { let response = request_app(setup_monitoring_endpoint().app(), "nodeVersion").await; assert_eq!(response.status(), StatusCode::OK); - let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); + let body = to_bytes(response.into_body()).await.unwrap(); assert_eq!(&body[..], TEST_VERSION.as_bytes()); } @@ -50,16 +52,16 @@ async fn test_ready() { #[tokio::test] async fn test_endpoint_as_server() { - tokio::spawn(async move { setup_monitoring_endpoint().run().await }); - tokio::task::yield_now().await; + spawn(async move { setup_monitoring_endpoint().run().await }); + yield_now().await; let MonitoringEndpointConfig { ip, port } = MonitoringEndpointConfig::default(); - let client = hyper::Client::new(); + let client = Client::new(); let response = client.request(build_request(&ip, port, "nodeVersion")).await.unwrap(); assert_eq!(response.status(), StatusCode::OK); - let body = hyper::body::to_bytes(response.into_body()).await.unwrap(); + let body = to_bytes(response.into_body()).await.unwrap(); assert_eq!(&body[..], TEST_VERSION.as_bytes()); } diff --git a/crates/monitoring_endpoint/src/test_utils.rs b/crates/monitoring_endpoint/src/test_utils.rs index 0dafda9194..89698a3d0b 100644 --- a/crates/monitoring_endpoint/src/test_utils.rs +++ b/crates/monitoring_endpoint/src/test_utils.rs @@ -4,6 +4,7 @@ use std::time::Duration; use axum::body::Body; use axum::http::Request; use hyper::client::HttpConnector; +use hyper::Client; use tracing::info; use crate::monitoring_endpoint::MONITORING_PREFIX; @@ -13,12 +14,12 @@ use crate::monitoring_endpoint::MONITORING_PREFIX; /// Client for querying 'alive' status of an http server. pub struct IsAliveClient { socket: SocketAddr, - client: hyper::Client, + client: Client, } impl IsAliveClient { pub fn new(socket: SocketAddr) -> Self { - let client = hyper::Client::new(); + let client = Client::new(); Self { socket, client } }