#![allow(clippy::all)]
#![allow(warnings)]
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(clippy::needless_borrows_for_generic_args)]
#![allow(clippy::assertions_on_constants)]
#![allow(clippy::type_complexity)]
#![allow(clippy::never_loop)]
#![allow(clippy::collapsible_if)]
use rpcnet::{RpcConfig, RpcServer};
use std::time::Duration;
fn test_config() -> RpcConfig {
RpcConfig::new("certs/test_cert.pem", "127.0.0.1:0")
.with_key_path("certs/test_key.pem")
.with_server_name("localhost")
}
#[tokio::test]
async fn test_streaming_handler_registration() {
let server = RpcServer::new(test_config());
server
.register_streaming("test_stream", |_request_stream| async move {
Box::pin(async_stream::stream! {
yield Ok(b"test".to_vec());
})
as std::pin::Pin<
Box<dyn futures::Stream<Item = Result<Vec<u8>, rpcnet::RpcError>> + Send>,
>
})
.await;
assert!(true);
}
#[tokio::test]
async fn test_streaming_server_setup() {
let mut server = RpcServer::new(test_config());
server
.register_streaming("simple_stream", |_request_stream| async move {
Box::pin(async_stream::stream! {
for i in 0..3 {
yield Ok(format!("message_{}", i).into_bytes());
}
})
as std::pin::Pin<
Box<dyn futures::Stream<Item = Result<Vec<u8>, rpcnet::RpcError>> + Send>,
>
})
.await;
let result = server.bind();
assert!(
result.is_ok(),
"Server should bind successfully with streaming handlers"
);
}
#[tokio::test]
async fn test_streaming_types_compilation() {
fn create_handler() -> impl Fn(
std::pin::Pin<Box<dyn futures::Stream<Item = Vec<u8>> + Send>>,
) -> std::pin::Pin<
Box<
dyn futures::Future<
Output = std::pin::Pin<
Box<dyn futures::Stream<Item = Result<Vec<u8>, rpcnet::RpcError>> + Send>,
>,
> + Send,
>,
> + Send
+ Sync
+ Clone {
|_request_stream| {
Box::pin(async move {
Box::pin(async_stream::stream! {
yield Ok(b"test".to_vec());
})
as std::pin::Pin<
Box<dyn futures::Stream<Item = Result<Vec<u8>, rpcnet::RpcError>> + Send>,
>
})
}
}
let _handler = create_handler();
assert!(true, "Streaming types should compile");
}
#[tokio::test]
async fn test_streaming_no_infinite_loops() {
let timeout_result = tokio::time::timeout(Duration::from_secs(5), async {
let server = RpcServer::new(test_config());
server
.register_streaming("timeout_test", |_request_stream| async move {
Box::pin(async_stream::stream! {
yield Ok(b"done".to_vec());
})
as std::pin::Pin<
Box<dyn futures::Stream<Item = Result<Vec<u8>, rpcnet::RpcError>> + Send>,
>
})
.await;
"completed"
})
.await;
assert!(
timeout_result.is_ok(),
"Streaming registration should not hang"
);
assert_eq!(timeout_result.unwrap(), "completed");
}