mod common;
use tokio::io::{AsyncReadExt, AsyncWriteExt};
#[tokio::test]
async fn write_half_close_keeps_read_open() {
let (client, server) = common::pair(64 * 1024);
let server_task = tokio::spawn({
let server = server.clone();
async move {
let mut s = server.accept().await.unwrap();
let mut buf = Vec::new();
s.read_to_end(&mut buf).await.unwrap();
assert_eq!(buf, b"hello");
s.write_all(b"world").await.unwrap();
s.shutdown().await.unwrap();
}
});
let mut stream = client.open().await.unwrap();
stream.write_all(b"hello").await.unwrap();
stream.shutdown().await.unwrap();
let mut got = Vec::new();
stream.read_to_end(&mut got).await.unwrap();
assert_eq!(got, b"world");
server_task.await.unwrap();
client.close().await;
server.close().await;
}