#![cfg(all(target_os = "linux", feature = "net"))]
#![cfg(not(any(miri, loom)))]
use std::{io::Write, net::TcpStream};
use kwokka::{net::TcpListener, runtime::Runtime};
#[test]
fn the_facade_accepts_and_recvs_a_loopback_payload() {
let Ok(listener) = TcpListener::bind("127.0.0.1:0") else {
panic!("binding a loopback listener must succeed");
};
let Ok(addr) = listener.local_addr() else {
panic!("the listener must report its local address");
};
let payload = b"kwokka facade socket round trip";
let Ok(mut client) = TcpStream::connect(addr) else {
panic!("connecting to the loopback listener must succeed");
};
let Ok(()) = client.write_all(payload) else {
panic!("the client write must succeed");
};
let Ok(mut runtime) = Runtime::affine() else {
panic!("the affine runtime must build on this host");
};
let outcome = runtime.block_on(async {
let stream = listener.accept().await?;
let (result, buf) = stream.recv::<64>().await;
let received = result?;
Ok::<_, std::io::Error>((received, buf))
});
drop(client);
let Ok((received, buf)) = outcome else {
panic!("the facade accept and recv must resolve without error");
};
assert_eq!(
received,
payload.len(),
"the recv drained the full payload the client sent",
);
assert_eq!(
&buf[..received],
&payload[..],
"the facade reads back the bytes the peer sent",
);
}