From 8f0fdfaea95d67efa07fa41bb29e600149a538bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E8=97=8D+85CD?= <50108258+kwaa@users.noreply.github.com> Date: Thu, 25 Jul 2024 17:21:46 +0800 Subject: [PATCH] refactor(tests): use axum::serve --- src/activity_queue.rs | 11 +++++++---- src/activity_sending.rs | 11 +++++++---- 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/src/activity_queue.rs b/src/activity_queue.rs index 20852bd..ad25402 100644 --- a/src/activity_queue.rs +++ b/src/activity_queue.rs @@ -424,6 +424,7 @@ mod tests { use bytes::Bytes; use http::{HeaderMap, StatusCode}; use std::time::Instant; + use tokio::net::TcpListener; use tracing::debug; // This will periodically send back internal errors to test the retry @@ -451,10 +452,12 @@ mod tests { .route("/", post(dodgy_handler)) .with_state(state); - axum::Server::bind(&"0.0.0.0:8002".parse().unwrap()) - .serve(app.into_make_service()) - .await - .unwrap(); + axum::serve( + TcpListener::bind("0.0.0.0:8002").await.unwrap(), + app.into_make_service(), + ) + .await + .unwrap(); } #[tokio::test(flavor = "multi_thread")] diff --git a/src/activity_sending.rs b/src/activity_sending.rs index f9023ce..3b27e2a 100644 --- a/src/activity_sending.rs +++ b/src/activity_sending.rs @@ -232,6 +232,7 @@ mod tests { sync::{atomic::AtomicUsize, Arc}, time::Instant, }; + use tokio::net::TcpListener; use tracing::info; // This will periodically send back internal errors to test the retry @@ -251,10 +252,12 @@ mod tests { .route("/", post(dodgy_handler)) .with_state(state); - axum::Server::bind(&"0.0.0.0:8001".parse().unwrap()) - .serve(app.into_make_service()) - .await - .unwrap(); + axum::serve( + TcpListener::bind("0.0.0.0:8002").await.unwrap(), + app.into_make_service(), + ) + .await + .unwrap(); } #[tokio::test(flavor = "multi_thread")]