-
Notifications
You must be signed in to change notification settings - Fork 225
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
submit all op before uring drop #245
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -22,6 +22,7 @@ async fn read_hello(file: &File) { | |
async fn basic_read() { | ||
let mut tempfile = tempfile(); | ||
tempfile.write_all(HELLO).unwrap(); | ||
tempfile.as_file_mut().sync_data().unwrap(); | ||
|
||
let file = File::open(tempfile.path()).await.unwrap(); | ||
read_hello(&file).await; | ||
|
@@ -31,6 +32,7 @@ async fn basic_read() { | |
async fn basic_read_exact() { | ||
let mut tempfile = tempfile(); | ||
tempfile.write_all(HELLO).unwrap(); | ||
tempfile.as_file_mut().sync_data().unwrap(); | ||
|
||
let file = File::open(tempfile.path()).await.unwrap(); | ||
let buf = Vec::with_capacity(HELLO.len()); | ||
|
@@ -49,6 +51,7 @@ async fn basic_write() { | |
|
||
let file = File::create(tempfile.path()).await.unwrap(); | ||
file.write_at(HELLO, 0).await.0.unwrap(); | ||
file.sync_all().await.unwrap(); | ||
|
||
let file = std::fs::read(tempfile.path()).unwrap(); | ||
assert_eq!(file, HELLO); | ||
|
@@ -60,6 +63,7 @@ async fn basic_write_all() { | |
|
||
let file = File::create(tempfile.path()).await.unwrap(); | ||
file.write_all_at(HELLO, 0).await.0.unwrap(); | ||
file.sync_all().await.unwrap(); | ||
|
||
let file = std::fs::read(tempfile.path()).unwrap(); | ||
assert_eq!(file, HELLO); | ||
|
@@ -69,6 +73,7 @@ async fn basic_write_all() { | |
async fn cancel_read() { | ||
let mut tempfile = tempfile(); | ||
tempfile.write_all(HELLO).unwrap(); | ||
tempfile.as_file_mut().sync_data().unwrap(); | ||
|
||
let file = File::open(tempfile.path()).await.unwrap(); | ||
|
||
|
@@ -82,6 +87,7 @@ async fn cancel_read() { | |
async fn explicit_close() { | ||
let mut tempfile = tempfile(); | ||
tempfile.write_all(HELLO).unwrap(); | ||
tempfile.as_file_mut().sync_data().unwrap(); | ||
|
||
let file = File::open(tempfile.path()).await.unwrap(); | ||
#[cfg(unix)] | ||
|
@@ -91,7 +97,7 @@ async fn explicit_close() { | |
|
||
file.close().await.unwrap(); | ||
|
||
assert_invalid_fd(fd); | ||
assert_invalid_fd(fd, tempfile.as_file().metadata().unwrap()); | ||
} | ||
|
||
#[monoio::test_all] | ||
|
@@ -101,6 +107,7 @@ async fn drop_open() { | |
// Do something else | ||
let file_w = File::create(tempfile.path()).await.unwrap(); | ||
file_w.write_at(HELLO, 0).await.0.unwrap(); | ||
file_w.sync_all().await.unwrap(); | ||
|
||
let file = std::fs::read(tempfile.path()).unwrap(); | ||
assert_eq!(file, HELLO); | ||
|
@@ -125,7 +132,7 @@ fn drop_off_runtime() { | |
let fd = file.as_raw_handle(); | ||
drop(file); | ||
|
||
assert_invalid_fd(fd); | ||
assert_invalid_fd(fd, tempfile.as_file().metadata().unwrap()); | ||
} | ||
|
||
#[monoio::test_all] | ||
|
@@ -158,13 +165,29 @@ async fn poll_once(future: impl std::future::Future) { | |
.await; | ||
} | ||
|
||
fn assert_invalid_fd(fd: RawFd) { | ||
fn assert_invalid_fd(fd: RawFd, base: std::fs::Metadata) { | ||
use std::fs::File; | ||
#[cfg(unix)] | ||
let mut f = unsafe { File::from_raw_fd(fd) }; | ||
let f = unsafe { File::from_raw_fd(fd) }; | ||
#[cfg(windows)] | ||
let mut f = unsafe { File::from_raw_handle(fd) }; | ||
let mut buf = vec![]; | ||
|
||
assert!(f.read_to_end(&mut buf).is_err()); | ||
let f = unsafe { File::from_raw_handle(fd) }; | ||
|
||
let meta = f.metadata(); | ||
std::mem::forget(f); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Need |
||
|
||
if let Ok(meta) = meta { | ||
if !meta.is_file() { | ||
return; | ||
} | ||
|
||
#[cfg(unix)] | ||
{ | ||
use std::os::unix::fs::MetadataExt; | ||
let inode = meta.ino(); | ||
let actual = base.ino(); | ||
if inode == actual { | ||
panic!(); | ||
} | ||
} | ||
} | ||
} |
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.
Just
flush
make sure that the content can be read.