#![cfg(feature = "comms")]
#![cfg(all(unix, feature = "bus-impl"))]
use futures_util::StreamExt;
use ntest::timeout;
use test_log::test;
use zbus::{Connection, Guid, connection::Builder};
#[cfg(feature = "default-rt")]
#[test]
#[timeout(15000)]
fn build_message_stream_does_not_drop_pipelined_hello_zruntime() {
futures_lite::future::block_on(async {
let (s0, s1) = std::os::unix::net::UnixStream::pair().unwrap();
let guid = Guid::generate();
build_message_stream_does_not_drop_pipelined_hello(
Builder::unix_stream(s0).server(guid).p2p(),
Builder::unix_stream(s1),
)
.await;
});
}
#[cfg(feature = "tokio")]
#[test]
#[timeout(15000)]
fn build_message_stream_does_not_drop_pipelined_hello_tokio() {
tokio::runtime::Runtime::new().unwrap().block_on(async {
let (s0, s1) = std::os::unix::net::UnixStream::pair().unwrap();
let guid = Guid::generate();
build_message_stream_does_not_drop_pipelined_hello(
Builder::unix_stream(s0).server(guid).p2p(),
Builder::unix_stream(s1),
)
.await;
});
}
async fn build_message_stream_does_not_drop_pipelined_hello(
server_builder: Builder<'_>,
client_builder: Builder<'_>,
) {
let server = async {
let mut stream = server_builder.build_message_stream().await.unwrap();
let hello = stream
.next()
.await
.expect("stream terminated unexpectedly")
.unwrap();
assert_eq!(hello.header().member().unwrap().as_str(), "Hello");
let conn = Connection::from(stream);
conn.reply(&hello.header(), &(":1.1",)).await.unwrap();
};
let ((), client) = futures_util::join!(server, client_builder.build());
let _client_conn = client.unwrap();
}