use super::mock::{AlwaysDegraded, AlwaysHealthy, AlwaysUnhealthy, HangingCheck, PanickingCheck};
use super::*;
use crate::config::GarrisonConfig;
use std::sync::Arc;
#[cfg(any(feature = "db-postgres", feature = "db-mysql", feature = "cache-redis"))]
struct HangDao;
#[cfg(any(feature = "db-postgres", feature = "db-mysql", feature = "cache-redis"))]
#[async_trait::async_trait]
impl crate::dao::GarrisonDao for HangDao {
async fn get(&self, _key: &str) -> crate::error::GarrisonResult<Option<String>> {
tokio::time::sleep(std::time::Duration::from_secs(10)).await;
Ok(None)
}
async fn set(
&self,
_key: &str,
_value: &str,
_ttl_seconds: u64,
) -> crate::error::GarrisonResult<()> {
Ok(())
}
async fn update(&self, _key: &str, _value: &str) -> crate::error::GarrisonResult<()> {
Ok(())
}
async fn expire(&self, _key: &str, _seconds: u64) -> crate::error::GarrisonResult<()> {
Ok(())
}
async fn delete(&self, _key: &str) -> crate::error::GarrisonResult<()> {
Ok(())
}
crate::atomic_test_fallback!();
}
#[test]
fn health_status_serializes_to_lowercase() {
assert_eq!(
serde_json::to_string(&HealthStatus::Healthy).unwrap(),
"\"healthy\""
);
assert_eq!(
serde_json::to_string(&HealthStatus::Degraded).unwrap(),
"\"degraded\""
);
assert_eq!(
serde_json::to_string(&HealthStatus::Unhealthy).unwrap(),
"\"unhealthy\""
);
}
#[test]
fn health_status_deserializes_from_lowercase() {
let s: HealthStatus = serde_json::from_str("\"healthy\"").unwrap();
assert_eq!(s, HealthStatus::Healthy);
let s: HealthStatus = serde_json::from_str("\"degraded\"").unwrap();
assert_eq!(s, HealthStatus::Degraded);
let s: HealthStatus = serde_json::from_str("\"unhealthy\"").unwrap();
assert_eq!(s, HealthStatus::Unhealthy);
}
#[test]
fn health_status_equality() {
assert_ne!(HealthStatus::Healthy, HealthStatus::Unhealthy);
assert_eq!(HealthStatus::Healthy, HealthStatus::Healthy);
}
#[tokio::test]
async fn empty_registry_returns_healthy() {
let registry = HealthRegistry::new();
let report = registry.check_all().await;
assert_eq!(report.overall, HealthStatus::Healthy);
assert!(report.checks.is_empty());
}
#[tokio::test]
async fn registry_all_healthy_returns_healthy() {
let mut registry = HealthRegistry::new();
registry.register(Box::new(AlwaysHealthy));
let report = registry.check_all().await;
assert_eq!(report.overall, HealthStatus::Healthy);
assert_eq!(report.checks.len(), 1);
assert_eq!(report.checks[0].name, "always-healthy");
assert_eq!(report.checks[0].status, HealthStatus::Healthy);
}
#[test]
fn with_check_timeout_overrides_default() {
let registry = HealthRegistry::new().with_check_timeout(std::time::Duration::from_millis(50));
assert_eq!(registry.check_timeout, std::time::Duration::from_millis(50));
}
#[tokio::test]
async fn registry_panicking_check_is_isolated_as_unhealthy() {
let mut registry = HealthRegistry::new();
registry.register(Box::new(AlwaysHealthy));
registry.register(Box::new(PanickingCheck));
let report = registry.check_all().await;
assert_eq!(report.overall, HealthStatus::Unhealthy);
let panicked = report
.checks
.iter()
.find(|c| c.name == "panicking")
.expect("应有 panicking 检查项");
assert_eq!(panicked.status, HealthStatus::Unhealthy);
assert_eq!(
panicked.message.as_deref(),
Some("check failed"),
"HTTP 响应只暴露通用描述,不泄漏 panic 细节"
);
}
#[tokio::test]
async fn registry_hanging_check_times_out_as_unhealthy() {
let mut registry =
HealthRegistry::new().with_check_timeout(std::time::Duration::from_millis(20));
registry.register(Box::new(HangingCheck));
let report = registry.check_all().await;
assert_eq!(report.overall, HealthStatus::Unhealthy);
assert_eq!(report.checks.len(), 1);
assert_eq!(report.checks[0].status, HealthStatus::Unhealthy);
}
#[tokio::test]
async fn registry_with_unhealthy_returns_unhealthy() {
let mut registry = HealthRegistry::new();
registry.register(Box::new(AlwaysHealthy));
registry.register(Box::new(AlwaysUnhealthy));
let report = registry.check_all().await;
assert_eq!(report.overall, HealthStatus::Unhealthy);
assert_eq!(report.checks.len(), 2);
let unhealthy_check = report
.checks
.iter()
.find(|c| c.name == "always-unhealthy")
.expect("should have always-unhealthy check");
assert_eq!(unhealthy_check.status, HealthStatus::Unhealthy);
assert!(unhealthy_check.message.is_some());
}
#[tokio::test]
async fn registry_with_degraded_and_no_unhealthy_returns_degraded() {
let mut registry = HealthRegistry::new();
registry.register(Box::new(AlwaysHealthy));
registry.register(Box::new(AlwaysDegraded));
let report = registry.check_all().await;
assert_eq!(report.overall, HealthStatus::Degraded);
}
#[tokio::test]
async fn registry_unhealthy_overrides_degraded() {
let mut registry = HealthRegistry::new();
registry.register(Box::new(AlwaysDegraded));
registry.register(Box::new(AlwaysUnhealthy));
let report = registry.check_all().await;
assert_eq!(report.overall, HealthStatus::Unhealthy);
}
#[tokio::test]
async fn config_health_check_returns_healthy_for_valid_config() {
let config = Arc::new(GarrisonConfig::default_config());
let checker = ConfigHealthCheck::new(config);
assert_eq!(checker.name(), "config");
let result = checker.check().await.unwrap();
assert_eq!(result, HealthStatus::Healthy);
}
#[tokio::test]
async fn config_health_check_returns_unhealthy_for_invalid_config() {
let mut config = GarrisonConfig::default_config();
config.timeout = -1; let checker = ConfigHealthCheck::new(Arc::new(config));
let result = checker.check().await;
assert!(result.is_err());
}
#[cfg(all(feature = "cache-memory", not(feature = "cache-redis")))]
#[tokio::test]
async fn cache_health_check_returns_healthy() {
let checker = CacheHealthCheck::new();
assert_eq!(checker.name(), "cache");
let result = checker.check().await.unwrap();
assert_eq!(result, HealthStatus::Healthy);
}
#[cfg(all(
feature = "db-sqlite",
not(any(feature = "db-postgres", feature = "db-mysql"))
))]
#[tokio::test]
async fn db_health_check_returns_healthy() {
let checker = DbHealthCheck::new();
assert_eq!(checker.name(), "database");
let result = checker.check().await.unwrap();
assert_eq!(result, HealthStatus::Healthy);
}
#[cfg(any(feature = "db-postgres", feature = "db-mysql"))]
#[tokio::test]
#[serial_test::serial]
async fn db_health_check_unhealthy_when_manager_uninitialized() {
crate::manager::GarrisonManager::reset_for_test();
assert!(
!crate::manager::GarrisonManager::is_initialized(),
"测试前置:manager 必须未初始化"
);
let checker = DbHealthCheck::new();
let status = checker.check().await.expect("check 应返回 Ok 而非 Err");
assert_eq!(
status,
HealthStatus::Unhealthy,
"manager 未初始化时 DbHealthCheck 应返回 Unhealthy(而非误报 Healthy)"
);
}
#[cfg(any(feature = "db-postgres", feature = "db-mysql"))]
#[tokio::test]
#[serial_test::serial]
async fn db_health_check_degraded_without_pool() {
use crate::manager::GarrisonManager;
use crate::stp::GarrisonInterface;
GarrisonManager::reset_for_test();
let dao: Arc<dyn crate::dao::GarrisonDao> = Arc::new(crate::dao::InMemoryDao::new());
let config = Arc::new(GarrisonConfig::default_config());
let interface: Arc<dyn GarrisonInterface> = Arc::new(crate::stp::mock::MockInterface);
GarrisonManager::builder()
.dao(dao)
.config(config)
.interface(interface)
.build()
.await
.expect("init manager 应成功");
let checker = DbHealthCheck::new();
let status = checker.check().await.expect("check 应返回 Ok 而非 Err");
assert_eq!(
status,
HealthStatus::Degraded,
"未注入连接池时 DbHealthCheck 应返回 Degraded(不误报 Healthy)"
);
GarrisonManager::reset_for_test();
}
#[cfg(all(
any(feature = "db-postgres", feature = "db-mysql"),
feature = "db-sqlite"
))]
#[tokio::test]
async fn db_health_check_with_pool_pings_real_db() {
use crate::manager::GarrisonManager;
use crate::stp::GarrisonInterface;
GarrisonManager::reset_for_test();
let dao: Arc<dyn crate::dao::GarrisonDao> = Arc::new(crate::dao::InMemoryDao::new());
let config = Arc::new(GarrisonConfig::default_config());
let interface: Arc<dyn GarrisonInterface> = Arc::new(crate::stp::mock::MockInterface);
GarrisonManager::builder()
.dao(dao)
.config(config)
.interface(interface)
.build()
.await
.expect("init manager 应成功");
let pool = crate::dao::init_dbnexus("sqlite::memory:")
.await
.expect("sqlite 内存池应创建成功");
let checker = DbHealthCheck::with_pool(pool);
let status = checker.check().await.expect("check 应返回 Ok 而非 Err");
assert_eq!(
status,
HealthStatus::Healthy,
"注入连接池且数据库可达时应返回 Healthy(真实 ping 通过)"
);
GarrisonManager::reset_for_test();
}
#[cfg(feature = "cache-redis")]
#[tokio::test]
#[serial_test::serial]
async fn cache_health_check_returns_unhealthy_on_probe_timeout() {
use crate::dao::GarrisonDao;
use crate::manager::GarrisonManager;
use crate::stp::GarrisonInterface;
use std::time::{Duration, Instant};
GarrisonManager::reset_for_test();
let dao: Arc<dyn GarrisonDao> = Arc::new(HangDao);
let config = Arc::new(GarrisonConfig::default_config());
let interface: Arc<dyn GarrisonInterface> = Arc::new(crate::stp::mock::MockInterface);
GarrisonManager::builder()
.dao(dao)
.config(config)
.interface(interface)
.build()
.await
.expect("init with HangDao 应成功(init 不调用 dao.get)");
assert!(
GarrisonManager::is_initialized(),
"测试前置:manager 必须已初始化"
);
let checker = CacheHealthCheck::new();
let start = Instant::now();
let status = checker
.check()
.await
.expect("check 应返回 Ok 而非 Err(超时映射为 Unhealthy,不是 Err)");
let elapsed = start.elapsed();
assert_eq!(
status,
HealthStatus::Unhealthy,
"dao hang 时 CacheHealthCheck 应在 HEALTH_PROBE_TIMEOUT 内返回 Unhealthy"
);
assert!(
elapsed < Duration::from_secs(5),
"应在 HEALTH_PROBE_TIMEOUT(2s)附近返回,实际耗时: {:?}",
elapsed
);
GarrisonManager::reset_for_test();
}
#[cfg(feature = "cache-redis")]
#[tokio::test]
#[serial_test::serial]
async fn cache_health_check_unhealthy_when_manager_uninitialized() {
crate::manager::GarrisonManager::reset_for_test();
assert!(
!crate::manager::GarrisonManager::is_initialized(),
"测试前置:manager 必须未初始化"
);
let checker = CacheHealthCheck::new();
let status = checker.check().await.expect("check 应返回 Ok 而非 Err");
assert_eq!(
status,
HealthStatus::Unhealthy,
"manager 未初始化时 CacheHealthCheck 应返回 Unhealthy(而非误报 Healthy)"
);
}
#[cfg(any(feature = "db-postgres", feature = "db-mysql"))]
#[tokio::test]
#[serial_test::serial]
async fn db_health_check_returns_degraded_without_pool_even_when_dao_hangs() {
use crate::dao::GarrisonDao;
use crate::manager::GarrisonManager;
use crate::stp::GarrisonInterface;
use std::time::{Duration, Instant};
GarrisonManager::reset_for_test();
let dao: Arc<dyn GarrisonDao> = Arc::new(HangDao);
let config = Arc::new(GarrisonConfig::default_config());
let interface: Arc<dyn GarrisonInterface> = Arc::new(crate::stp::mock::MockInterface);
GarrisonManager::builder()
.dao(dao)
.config(config)
.interface(interface)
.build()
.await
.expect("init with HangDao 应成功(init 不调用 dao.get)");
assert!(
GarrisonManager::is_initialized(),
"测试前置:manager 必须已初始化"
);
let checker = DbHealthCheck::new();
let start = Instant::now();
let status = checker
.check()
.await
.expect("check 应返回 Ok 而非 Err(无池映射为 Degraded,不是 Err)");
let elapsed = start.elapsed();
assert_eq!(
status,
HealthStatus::Degraded,
"未注入连接池时 DbHealthCheck 应诚实降级为 Degraded(不探测 dao.get,不误报 Healthy)"
);
assert!(
elapsed < Duration::from_secs(1),
"无池分支应立即返回(不等待 dao),实际耗时: {:?}",
elapsed
);
GarrisonManager::reset_for_test();
}
#[test]
fn health_report_serializes_correctly() {
let report = HealthReport {
overall: HealthStatus::Degraded,
checks: vec![CheckResult {
name: "cache".to_string(),
status: HealthStatus::Degraded,
message: Some("high latency".to_string()),
}],
};
let json = serde_json::to_string(&report).unwrap();
assert!(json.contains("\"overall\":\"degraded\""));
assert!(json.contains("\"name\":\"cache\""));
assert!(json.contains("\"status\":\"degraded\""));
assert!(json.contains("\"message\":\"high latency\""));
}
#[test]
fn health_report_skips_none_message() {
let report = HealthReport {
overall: HealthStatus::Healthy,
checks: vec![CheckResult {
name: "config".to_string(),
status: HealthStatus::Healthy,
message: None,
}],
};
let json = serde_json::to_string(&report).unwrap();
assert!(!json.contains("message"));
}
#[cfg(feature = "web-axum")]
#[tokio::test]
async fn test_axum_live_returns_200() {
use axum::body::Body;
use axum::http::{Request, StatusCode};
use tower::ServiceExt;
let registry = Arc::new(HealthRegistry::new());
let app = super::axum_routes::health_routes(registry);
let resp = app
.oneshot(
Request::builder()
.method("GET")
.uri("/health/live")
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
}
#[cfg(feature = "web-axum")]
#[tokio::test]
async fn test_axum_ready_returns_200_when_healthy() {
use axum::body::Body;
use axum::http::{Request, StatusCode};
use tower::ServiceExt;
let mut registry = HealthRegistry::new();
registry.register(Box::new(AlwaysHealthy));
let app = super::axum_routes::health_routes(Arc::new(registry));
let resp = app
.oneshot(
Request::builder()
.method("GET")
.uri("/health/ready")
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
}
#[cfg(feature = "web-axum")]
#[tokio::test]
async fn test_axum_ready_returns_200_when_degraded() {
use axum::body::Body;
use axum::http::{Request, StatusCode};
use tower::ServiceExt;
let mut registry = HealthRegistry::new();
registry.register(Box::new(AlwaysDegraded));
let app = super::axum_routes::health_routes(Arc::new(registry));
let resp = app
.oneshot(
Request::builder()
.method("GET")
.uri("/health/ready")
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::OK);
}
#[cfg(feature = "web-axum")]
#[tokio::test]
async fn test_axum_ready_returns_503_when_unhealthy() {
use axum::body::Body;
use axum::http::{Request, StatusCode};
use tower::ServiceExt;
let mut registry = HealthRegistry::new();
registry.register(Box::new(AlwaysUnhealthy));
let app = super::axum_routes::health_routes(Arc::new(registry));
let resp = app
.oneshot(
Request::builder()
.method("GET")
.uri("/health/ready")
.body(Body::empty())
.unwrap(),
)
.await
.unwrap();
assert_eq!(resp.status(), StatusCode::SERVICE_UNAVAILABLE);
}
#[cfg(feature = "web-warp")]
#[tokio::test]
async fn test_warp_live_filter_returns_200() {
use super::warp_routes::live_filter;
use warp::http::StatusCode;
let resp = warp::test::request()
.method("GET")
.path("/health/live")
.reply(&live_filter())
.await;
assert_eq!(resp.status(), StatusCode::OK);
}
#[cfg(feature = "web-warp")]
#[tokio::test]
async fn test_warp_ready_filter_returns_200_when_healthy() {
use super::warp_routes::ready_filter;
use warp::http::StatusCode;
let mut registry = HealthRegistry::new();
registry.register(Box::new(AlwaysHealthy));
let filter = ready_filter(Arc::new(registry));
let resp = warp::test::request()
.method("GET")
.path("/health/ready")
.reply(&filter)
.await;
assert_eq!(resp.status(), StatusCode::OK);
}
#[cfg(feature = "web-warp")]
#[tokio::test]
async fn test_warp_ready_filter_returns_503_when_unhealthy() {
use super::warp_routes::ready_filter;
use warp::http::StatusCode;
let mut registry = HealthRegistry::new();
registry.register(Box::new(AlwaysUnhealthy));
let filter = ready_filter(Arc::new(registry));
let resp = warp::test::request()
.method("GET")
.path("/health/ready")
.reply(&filter)
.await;
assert_eq!(resp.status(), StatusCode::SERVICE_UNAVAILABLE);
}
#[tokio::test]
async fn test_health_registry_default() {
let registry = HealthRegistry::default();
let report = registry.check_all().await;
assert_eq!(report.overall, HealthStatus::Healthy);
assert!(report.checks.is_empty());
}
#[test]
fn test_health_report_empty() {
let report = HealthReport::empty();
assert_eq!(report.overall, HealthStatus::Healthy);
assert!(report.checks.is_empty());
}
#[tokio::test]
async fn test_health_registry_register_chain() {
let mut registry = HealthRegistry::new();
registry
.register(Box::new(AlwaysHealthy))
.register(Box::new(AlwaysDegraded));
let report = registry.check_all().await;
assert_eq!(report.checks.len(), 2);
assert_eq!(report.overall, HealthStatus::Degraded);
}
#[cfg(feature = "cache-redis")]
#[tokio::test]
#[serial_test::serial]
async fn cache_health_check_default_returns_healthy_when_probe_succeeds() {
use crate::dao::GarrisonDao;
use crate::manager::GarrisonManager;
use crate::stp::GarrisonInterface;
GarrisonManager::reset_for_test();
let dao: Arc<dyn GarrisonDao> = Arc::new(crate::dao::InMemoryDao::new());
let config = Arc::new(GarrisonConfig::default_config());
let interface: Arc<dyn GarrisonInterface> = Arc::new(crate::stp::mock::MockInterface);
GarrisonManager::builder()
.dao(dao)
.config(config)
.interface(interface)
.build()
.await
.expect("init with InMemoryDao 应成功");
#[allow(clippy::default_constructed_unit_structs)]
let checker = CacheHealthCheck::default();
assert_eq!(checker.name(), "cache");
let status = checker.check().await.expect("check 应返回 Ok 而非 Err");
assert_eq!(
status,
HealthStatus::Healthy,
"dao.get 可达(Ok(Ok(_)))时探测应返回 Healthy"
);
GarrisonManager::reset_for_test();
}
#[cfg(all(feature = "cache-memory", not(feature = "cache-redis")))]
#[tokio::test]
async fn cache_health_check_default_impl_fast_path() {
#[allow(clippy::default_constructed_unit_structs)]
let checker = CacheHealthCheck::default();
assert_eq!(checker.name(), "cache");
let result = checker.check().await.unwrap();
assert_eq!(result, HealthStatus::Healthy);
}
#[cfg(all(
feature = "db-sqlite",
not(any(feature = "db-postgres", feature = "db-mysql"))
))]
#[tokio::test]
async fn db_health_check_default_impl_returns_healthy() {
#[allow(clippy::default_constructed_unit_structs)]
let checker = DbHealthCheck::default();
assert_eq!(checker.name(), "database");
let result = checker.check().await.unwrap();
assert_eq!(result, HealthStatus::Healthy);
}
#[cfg(feature = "web-warp")]
#[tokio::test]
async fn test_warp_health_filters_serves_live_and_ready() {
use super::warp_routes::health_filters;
use warp::http::StatusCode;
let mut registry = HealthRegistry::new();
registry.register(Box::new(AlwaysHealthy));
let filter = health_filters(Arc::new(registry));
let resp = warp::test::request()
.method("GET")
.path("/health/live")
.reply(&filter)
.await;
assert_eq!(resp.status(), StatusCode::OK, "合并 filter 应放行 live");
let resp = warp::test::request()
.method("GET")
.path("/health/ready")
.reply(&filter)
.await;
assert_eq!(resp.status(), StatusCode::OK, "合并 filter 应放行 ready");
}
#[cfg(feature = "web-warp")]
#[tokio::test]
async fn test_warp_ready_filter_returns_200_when_degraded() {
use super::warp_routes::ready_filter;
use warp::http::StatusCode;
let mut registry = HealthRegistry::new();
registry.register(Box::new(AlwaysDegraded));
let filter = ready_filter(Arc::new(registry));
let resp = warp::test::request()
.method("GET")
.path("/health/ready")
.reply(&filter)
.await;
assert_eq!(resp.status(), StatusCode::OK);
}
#[cfg(feature = "cache-redis")]
struct ErrorDao;
#[cfg(feature = "cache-redis")]
#[async_trait::async_trait]
impl crate::dao::GarrisonDao for ErrorDao {
async fn get(&self, _key: &str) -> crate::error::GarrisonResult<Option<String>> {
Err(crate::error::GarrisonError::Dao(
"health-probe-error".to_string(),
))
}
async fn set(
&self,
_key: &str,
_value: &str,
_ttl_seconds: u64,
) -> crate::error::GarrisonResult<()> {
Ok(())
}
async fn update(&self, _key: &str, _value: &str) -> crate::error::GarrisonResult<()> {
Ok(())
}
async fn expire(&self, _key: &str, _seconds: u64) -> crate::error::GarrisonResult<()> {
Ok(())
}
async fn delete(&self, _key: &str) -> crate::error::GarrisonResult<()> {
Ok(())
}
crate::atomic_test_fallback!();
}
#[cfg(feature = "cache-redis")]
#[tokio::test]
#[serial_test::serial]
async fn cache_health_check_unhealthy_when_probe_errors() {
use crate::dao::GarrisonDao;
use crate::manager::GarrisonManager;
use crate::stp::GarrisonInterface;
GarrisonManager::reset_for_test();
let dao: Arc<dyn GarrisonDao> = Arc::new(ErrorDao);
let config = Arc::new(GarrisonConfig::default_config());
let interface: Arc<dyn GarrisonInterface> = Arc::new(crate::stp::mock::MockInterface);
GarrisonManager::builder()
.dao(dao)
.config(config)
.interface(interface)
.build()
.await
.expect("init with ErrorDao 应成功(init 不调用 dao.get)");
let checker = CacheHealthCheck::new();
let status = checker.check().await.expect("check 应返回 Ok 而非 Err");
assert_eq!(
status,
HealthStatus::Unhealthy,
"dao.get 返回 Err 时探测应映射为 Unhealthy(而非 Err)"
);
GarrisonManager::reset_for_test();
}
#[cfg(feature = "web-actix")]
#[tokio::test]
async fn test_actix_health_routes_serve_live_and_ready() {
use actix_web::test::{call_service, init_service, TestRequest};
use actix_web::{http::StatusCode, web, App};
let healthy = Arc::new(HealthRegistry::new());
let app = init_service(
App::new()
.app_data(web::Data::new(healthy))
.configure(super::actix_routes::configure_health_routes),
)
.await;
let live = call_service(&app, TestRequest::get().uri("/health/live").to_request()).await;
assert_eq!(live.status(), StatusCode::OK, "liveness 进程存活即 200");
let ready = call_service(&app, TestRequest::get().uri("/health/ready").to_request()).await;
assert_eq!(
ready.status(),
StatusCode::OK,
"空 registry 聚合为 Healthy,readiness 应 200"
);
let mut unhealthy = HealthRegistry::new();
unhealthy.register(Box::new(AlwaysUnhealthy));
let app = init_service(
App::new()
.app_data(web::Data::new(Arc::new(unhealthy)))
.configure(super::actix_routes::configure_health_routes),
)
.await;
let ready = call_service(&app, TestRequest::get().uri("/health/ready").to_request()).await;
assert_eq!(
ready.status(),
StatusCode::SERVICE_UNAVAILABLE,
"任一检查项 Unhealthy 时 readiness 应 503"
);
}