#[ cfg( feature = "retry" ) ]
mod retry_calculation_tests
{
use crate::enhanced_retry_helpers::*;
use core::time::Duration;
#[ tokio::test ]
async fn test_exponential_backoff_calculation()
{
let config = EnhancedRetryConfig::new()
.with_base_delay( 1000 )
.with_max_delay( 30000 )
.with_jitter( 0 ) .with_backoff_multiplier( 2.0 );
let delay_0 = config.calculate_delay( 0 );
let delay_1 = config.calculate_delay( 1 );
let delay_2 = config.calculate_delay( 2 );
let delay_3 = config.calculate_delay( 3 );
assert_eq!( delay_0, Duration::from_millis( 1000 ) );
assert_eq!( delay_1, Duration::from_millis( 2000 ) );
assert_eq!( delay_2, Duration::from_millis( 4000 ) );
assert_eq!( delay_3, Duration::from_millis( 8000 ) );
}
#[ tokio::test ]
async fn test_delay_calculation_with_jitter()
{
let config = EnhancedRetryConfig::new()
.with_base_delay( 1000 )
.with_jitter( 500 );
let delay = config.calculate_delay( 0 );
assert!( delay >= Duration::from_millis( 1000 ) );
assert!( delay <= Duration::from_millis( 1500 ) );
}
#[ tokio::test ]
async fn test_delay_calculation_respects_max_delay()
{
let config = EnhancedRetryConfig::new()
.with_base_delay( 1000 )
.with_max_delay( 5000 )
.with_jitter( 0 )
.with_backoff_multiplier( 2.0 );
let delay = config.calculate_delay( 10 );
assert_eq!( delay, Duration::from_millis( 5000 ) );
}
}