-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
io: fix fill_buf by not calling poll_fill_buf twice (#4084)
- Loading branch information
Showing
2 changed files
with
41 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#![warn(rust_2018_idioms)] | ||
#![cfg(feature = "full")] | ||
|
||
use tempfile::NamedTempFile; | ||
use tokio::fs::File; | ||
use tokio::io::{AsyncBufReadExt, BufReader}; | ||
use tokio_test::assert_ok; | ||
|
||
#[tokio::test] | ||
async fn fill_buf_file() { | ||
let file = NamedTempFile::new().unwrap(); | ||
|
||
assert_ok!(std::fs::write(file.path(), b"hello")); | ||
|
||
let file = assert_ok!(File::open(file.path()).await); | ||
let mut file = BufReader::new(file); | ||
|
||
let mut contents = Vec::new(); | ||
|
||
loop { | ||
let consumed = { | ||
let buffer = assert_ok!(file.fill_buf().await); | ||
if buffer.is_empty() { | ||
break; | ||
} | ||
contents.extend_from_slice(buffer); | ||
buffer.len() | ||
}; | ||
|
||
file.consume(consumed); | ||
} | ||
|
||
assert_eq!(contents, b"hello"); | ||
} |