use std::io::Write;
use compio_io::AsyncRead;
use compio_net::TcpStream;
#[compio_macros::test]
async fn runtime_tcp_stream_blocking_read() {
let listener = std::net::TcpListener::bind("127.0.0.1:0").unwrap();
let addr = listener.local_addr().unwrap();
let connector = std::thread::spawn(move || std::net::TcpStream::connect(addr).unwrap());
let mut client = connector.join().unwrap();
let (server, _) = listener.accept().unwrap();
let mut stream = TcpStream::from_std(server).unwrap();
client.write_all(b"PIPELINED-FIRST-FRAME").unwrap();
client.flush().unwrap();
let bytes_read = stream.read(Vec::with_capacity(64)).await.0.unwrap();
assert_eq!(bytes_read, 21);
let reader =
compio_runtime::spawn(async move { stream.read(Vec::with_capacity(64)).await.0.unwrap() });
compio_runtime::spawn_blocking(|| {
std::thread::sleep(std::time::Duration::from_millis(100));
})
.await
.unwrap();
drop(reader);
drop(client);
}