Clean up Chinese comments and add comprehensive English README
- Replace all Chinese comments with English equivalents in: - src/health_monitor.rs - src/lib.rs - tests/integration_test.rs - Add comprehensive README.md with: - Project overview and features - Architecture diagram - Installation and configuration guide - Data format specifications - Health monitoring documentation - Troubleshooting guide
This commit is contained in:
@@ -4,10 +4,10 @@ use std::time::Duration;
|
||||
use tokio::time::sleep;
|
||||
use network_monitor::retry::{RetryConfig, retry_with_config};
|
||||
|
||||
/// 模拟网络故障的测试
|
||||
/// Test simulating network failure recovery
|
||||
#[tokio::test]
|
||||
async fn test_network_failure_recovery() {
|
||||
// 模拟一个会失败几次然后成功的操作
|
||||
// Simulate an operation that fails a few times then succeeds
|
||||
let attempt_count = Arc::new(AtomicU32::new(0));
|
||||
let max_failures = 3;
|
||||
|
||||
@@ -16,7 +16,7 @@ async fn test_network_failure_recovery() {
|
||||
initial_delay: Duration::from_millis(10),
|
||||
max_delay: Duration::from_millis(100),
|
||||
backoff_multiplier: 1.5,
|
||||
jitter: false, // 关闭抖动以便测试更可预测
|
||||
jitter: false, // Disable jitter for more predictable testing
|
||||
};
|
||||
|
||||
let attempt_count_clone = attempt_count.clone();
|
||||
@@ -26,10 +26,10 @@ async fn test_network_failure_recovery() {
|
||||
let current_attempt = attempt_count.fetch_add(1, Ordering::SeqCst) + 1;
|
||||
|
||||
if current_attempt <= max_failures {
|
||||
// 模拟网络错误
|
||||
// Simulate network error
|
||||
Err(format!("Network error on attempt {}", current_attempt))
|
||||
} else {
|
||||
// 模拟恢复成功
|
||||
// Simulate successful recovery
|
||||
Ok(format!("Success on attempt {}", current_attempt))
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ async fn test_network_failure_recovery() {
|
||||
assert_eq!(attempt_count.load(Ordering::SeqCst), 4);
|
||||
}
|
||||
|
||||
/// 测试连接超时场景
|
||||
/// Test connection timeout scenario
|
||||
#[tokio::test]
|
||||
async fn test_connection_timeout_scenario() {
|
||||
let config = RetryConfig {
|
||||
@@ -59,17 +59,17 @@ async fn test_connection_timeout_scenario() {
|
||||
async move {
|
||||
attempt_count.fetch_add(1, Ordering::SeqCst);
|
||||
|
||||
// 模拟连接超时
|
||||
// Simulate connection timeout
|
||||
sleep(Duration::from_millis(1)).await;
|
||||
Err("Connection timeout")
|
||||
}
|
||||
}).await;
|
||||
|
||||
assert!(result.is_err());
|
||||
assert_eq!(attempt_count.load(Ordering::SeqCst), 3); // 应该尝试了3次
|
||||
assert_eq!(attempt_count.load(Ordering::SeqCst), 3); // Should have attempted 3 times
|
||||
}
|
||||
|
||||
/// 测试快速恢复场景
|
||||
/// Test fast recovery scenario
|
||||
#[tokio::test]
|
||||
async fn test_fast_recovery() {
|
||||
let config = RetryConfig::fast();
|
||||
@@ -95,7 +95,7 @@ async fn test_fast_recovery() {
|
||||
assert_eq!(attempt_count.load(Ordering::SeqCst), 2);
|
||||
}
|
||||
|
||||
/// 测试慢速重试场景
|
||||
/// Test slow retry scenario
|
||||
#[tokio::test]
|
||||
async fn test_slow_retry_scenario() {
|
||||
let config = RetryConfig::slow();
|
||||
@@ -121,7 +121,7 @@ async fn test_slow_retry_scenario() {
|
||||
assert_eq!(attempt_count.load(Ordering::SeqCst), 3);
|
||||
}
|
||||
|
||||
/// 测试最大重试次数限制
|
||||
/// Test maximum retry limit
|
||||
#[tokio::test]
|
||||
async fn test_max_retry_limit() {
|
||||
let config = RetryConfig {
|
||||
|
Reference in New Issue
Block a user