use silent::{BoxedConnection, SocketAddr};
use std::sync::Arc;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
#[tokio::test]
async fn test_connection_service_trait() {
let call_count = Arc::new(tokio::sync::Mutex::new(0_u32));
let call_count_clone = call_count.clone();
let _handler = move |mut stream: BoxedConnection, _peer: SocketAddr| {
let count = call_count_clone.clone();
async move {
*count.lock().await += 1;
let mut buf = [0u8; 4];
stream.read_exact(&mut buf).await?;
stream.write_all(b"OK").await?;
Ok::<(), Box<dyn std::error::Error + Send + Sync>>(())
}
};
assert_eq!(*call_count.lock().await, 0);
}