| |
| |
|
|
| use std::time::Duration; |
| use crate::proxy::handlers::common::{determine_retry_strategy, should_rotate_account, RetryStrategy}; |
|
|
| |
|
|
| #[test] |
| fn test_retry_strategy_404() { |
| let strategy = determine_retry_strategy(404, "", false); |
| match strategy { |
| RetryStrategy::FixedDelay(d) => assert_eq!(d, Duration::from_millis(300)), |
| other => panic!("Expected FixedDelay(300ms), got {:?}", other), |
| } |
| } |
|
|
| #[test] |
| fn test_retry_strategy_429_no_delay() { |
| let strategy = determine_retry_strategy(429, "rate limited", false); |
| assert!( |
| matches!(strategy, RetryStrategy::LinearBackoff { base_ms: 5000 }), |
| "Expected LinearBackoff {{ base_ms: 5000 }}, got {:?}", |
| strategy |
| ); |
| } |
|
|
| #[test] |
| fn test_retry_strategy_503() { |
| let strategy = determine_retry_strategy(503, "", false); |
| assert!( |
| matches!(strategy, RetryStrategy::ExponentialBackoff { base_ms: 10000, max_ms: 60000 }), |
| "Expected ExponentialBackoff {{ base_ms: 10000, max_ms: 60000 }}, got {:?}", |
| strategy |
| ); |
| } |
|
|
| #[test] |
| fn test_retry_strategy_529() { |
| let strategy = determine_retry_strategy(529, "", false); |
| assert!( |
| matches!(strategy, RetryStrategy::ExponentialBackoff { base_ms: 10000, max_ms: 60000 }), |
| "Expected ExponentialBackoff {{ base_ms: 10000, max_ms: 60000 }}, got {:?}", |
| strategy |
| ); |
| } |
|
|
| #[test] |
| fn test_retry_strategy_500() { |
| let strategy = determine_retry_strategy(500, "", false); |
| assert!( |
| matches!(strategy, RetryStrategy::LinearBackoff { base_ms: 3000 }), |
| "Expected LinearBackoff {{ base_ms: 3000 }}, got {:?}", |
| strategy |
| ); |
| } |
|
|
| #[test] |
| fn test_retry_strategy_401_403() { |
| for status in [401, 403] { |
| let strategy = determine_retry_strategy(status, "", false); |
| match strategy { |
| RetryStrategy::FixedDelay(d) => assert_eq!(d, Duration::from_millis(200)), |
| other => panic!("Expected FixedDelay(200ms) for {}, got {:?}", status, other), |
| } |
| } |
| } |
|
|
| #[test] |
| fn test_retry_strategy_other() { |
| for status in [200, 201, 301, 418, 502] { |
| let strategy = determine_retry_strategy(status, "", false); |
| assert!( |
| matches!(strategy, RetryStrategy::NoRetry), |
| "Expected NoRetry for {}, got {:?}", |
| status, |
| strategy |
| ); |
| } |
| } |
|
|
| #[test] |
| fn test_retry_strategy_400_thinking_signature() { |
| let signatures = [ |
| "Invalid `signature` for thinking", |
| "Error with thinking.signature", |
| "thinking.thinking block failed", |
| "Corrupted thought signature detected", |
| ]; |
| for sig in signatures { |
| let strategy = determine_retry_strategy(400, sig, false); |
| match strategy { |
| RetryStrategy::FixedDelay(d) => assert_eq!(d, Duration::from_millis(200)), |
| other => panic!( |
| "Expected FixedDelay(200ms) for 400 + '{}', got {:?}", |
| sig, other |
| ), |
| } |
| } |
| } |
|
|
| #[test] |
| fn test_retry_strategy_400_no_signature() { |
| let strategy = determine_retry_strategy(400, "bad request", false); |
| assert!( |
| matches!(strategy, RetryStrategy::NoRetry), |
| "Expected NoRetry for 400 without signature, got {:?}", |
| strategy |
| ); |
| } |
|
|
| |
|
|
| #[test] |
| fn test_rotate_account_true_cases() { |
| for status in [429, 401, 403, 404, 500] { |
| assert!( |
| should_rotate_account(status, None), |
| "Expected should_rotate_account({}) == true", |
| status |
| ); |
| } |
| } |
|
|
| #[test] |
| fn test_rotate_account_false_cases() { |
| for status in [400, 503, 529, 200, 502] { |
| assert!( |
| !should_rotate_account(status, None), |
| "Expected should_rotate_account({}) == false", |
| status |
| ); |
| } |
| } |
|
|