mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-26 00:00:16 +02:00
tokio-util: stop polling StreamReader after EOF (#8332)
This commit is contained in:
@@ -33,3 +33,22 @@ async fn test_stream_reader() -> std::io::Result<()> {
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[tokio::test]
|
||||
async fn test_stream_reader_does_not_poll_after_eof() -> std::io::Result<()> {
|
||||
// the first poll of this stream will return `Poll::Ready(None)`,
|
||||
// and the second poll will panic
|
||||
let stream = futures::stream::unfold((), |_| async { None::<(std::io::Result<Bytes>, ())> });
|
||||
let read = StreamReader::new(stream);
|
||||
tokio::pin!(read);
|
||||
let mut buf = [0; 1];
|
||||
|
||||
// the first poll hits the inner stream,
|
||||
// and the inner stream returns `Poll::Ready(None)`.
|
||||
assert_eq!(read.read(&mut buf).await?, 0);
|
||||
// the second poll doesn't hit the inner stream,
|
||||
// so this `.read()` doesn't panic.
|
||||
assert_eq!(read.read(&mut buf).await?, 0);
|
||||
|
||||
Ok(())
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user