use knust::transport::BackoffConfig;
use knust::{ConnectionConfig, ConnectionType, Knx};
use std::time::Duration;
use tokio::time::sleep;
#[tokio::test]
async fn test_disconnect_protocol_handling() {
let config = ConnectionConfig {
connection_type: ConnectionType::Routing, auto_reconnect: true,
..Default::default()
};
let knx = Knx::new(config)
.await
.expect("Failed to create Knx instance");
knx.connect().await.expect("Failed to connect");
assert!(knx.is_connected().await);
knx.start().await.expect("Failed to start processing");
knx.disconnect().await.expect("Failed to disconnect");
assert!(!knx.is_connected().await);
sleep(Duration::from_millis(100)).await;
knx.stop().await;
println!("✓ Disconnect protocol handling test completed successfully");
}
#[tokio::test]
async fn test_reconnection_backoff_configuration() {
let config = ConnectionConfig {
connection_type: ConnectionType::Routing,
auto_reconnect: true,
reconnect_backoff: BackoffConfig {
initial_delay_ms: 500,
max_delay_ms: 5000,
multiplier: 1.5,
max_attempts: 5,
},
..Default::default()
};
let knx = Knx::new(config)
.await
.expect("Failed to create Knx instance");
assert!(knx.config().auto_reconnect);
assert_eq!(knx.config().reconnect_backoff.initial_delay_ms, 500);
assert_eq!(knx.config().reconnect_backoff.max_attempts, 5);
println!("✓ Reconnection backoff configuration test completed successfully");
}
#[tokio::test]
async fn test_control_event_system() {
use knust::application::ConnectionControlEvent;
let config = ConnectionConfig {
connection_type: ConnectionType::Routing,
..Default::default()
};
let _knx = Knx::new(config)
.await
.expect("Failed to create Knx instance");
let _ = ConnectionControlEvent::TunnelLost {
channel_id: 1,
reason: "Test disconnect".to_string(),
};
let _ = ConnectionControlEvent::SendDisconnectResponse { channel_id: 1 };
println!("✓ Control event system test completed successfully");
}