-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix futures_io::AsyncSeek implementaion for Compat #5783
Merged
Darksonn
merged 7 commits into
tokio-rs:master
from
dhruv9vats:tokio-util-compat-async-seek-fix
Jun 25, 2023
Merged
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
51c38cb
Return Poll::Pending until seek completes
dhruv9vats 076afe9
Use ready! and add test
dhruv9vats fd3f9d5
Merge remote-tracking branch 'upstream/master' into tokio-util-compat…
dhruv9vats 29a63dd
Attempt to fix CI
dhruv9vats 61f50a1
Remove incosistent unwarp use
dhruv9vats 8f4d239
Revert unintended Cargo.toml format
dhruv9vats b707b0a
Merge remote-tracking branch 'upstream/master' into tokio-util-compat…
dhruv9vats File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
dhruv9vats marked this conversation as resolved.
Show resolved
Hide resolved
|
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,43 @@ | ||
#![cfg(all(feature = "compat"))] | ||
#![cfg(not(target_os = "wasi"))] // WASI does not support all fs operations | ||
#![warn(rust_2018_idioms)] | ||
|
||
use futures_io::SeekFrom; | ||
use futures_util::{AsyncReadExt, AsyncSeekExt, AsyncWriteExt}; | ||
use tempfile::NamedTempFile; | ||
use tokio::fs::OpenOptions; | ||
use tokio_util::compat::TokioAsyncWriteCompatExt; | ||
|
||
#[tokio::test] | ||
async fn compat_file_seek() -> futures_util::io::Result<()> { | ||
let temp_file = NamedTempFile::new()?; | ||
let mut file = OpenOptions::new() | ||
.read(true) | ||
.write(true) | ||
.create(true) | ||
.open(temp_file) | ||
.await? | ||
.compat_write(); | ||
|
||
file.write_all(&[0, 1, 2, 3, 4, 5]).await?; | ||
file.write_all(&[6, 7]).await?; | ||
|
||
assert_eq!(file.stream_position().await?, 8); | ||
|
||
// Modify elements at position 2. | ||
assert_eq!(file.seek(SeekFrom::Start(2)).await?, 2); | ||
file.write_all(&[8, 9]).await?; | ||
|
||
file.flush().await?; | ||
|
||
// Verify we still have 8 elements. | ||
assert_eq!(file.seek(SeekFrom::End(0)).await?, 8); | ||
// Seek back to the start of the file to read and verify contents. | ||
file.seek(SeekFrom::Start(0)).await?; | ||
|
||
let mut buf = Vec::new(); | ||
let num_bytes = file.read_to_end(&mut buf).await?; | ||
assert_eq!(&buf[..num_bytes], &[0, 1, 8, 9, 4, 5, 6, 7]); | ||
|
||
Ok(()) | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding a dependency to add a test feels overkill.
But the thing is, the test only fails for a
tokio::fs::file::File
.Using something like
tokio::io::util::buf_writer::BufWriter
orstd::io::cursor::Cursor
seems to be working fine on latestupstream/master
:There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Darksonn, is there some alternative way to test this? And would it more sense to skip adding one if there is none?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This dependency already exists in the main Tokio crate, so adding it here doesn't actually add a new dependency.