Skip to content

tokio:issue-6374 : demonstrating Poll::Ready(Ok(n)) returned too early #7331

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

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions tokio/src/fs/file/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -976,3 +976,56 @@ fn busy_file_seek_error() {
let mut t = task::spawn(file.seek(SeekFrom::Start(0)));
assert_ready_err!(t.poll());
}

// issue 2 Demonstration
#[test]
fn open_write_old() {
let mut file = MockFile::default();
file.expect_inner_write()
.once()
.with(eq(HELLO))
.returning(|buf| Ok(buf.len()));

let mut file = File::from_std(file);

let mut t = task::spawn(file.write(HELLO));

assert_eq!(0, pool::len());

// This poll returns Ready even though the queued blocking write task hasn't run yet.`pool::run_one();` here
// This is the async contract violation we're fixing.
assert_ready_ok!(t.poll());

assert_eq!(1, pool::len());

pool::run_one();

assert!(!t.is_woken());

let mut t = task::spawn(file.flush());
assert_ready_ok!(t.poll());
}
#[test]
fn open_write_new() {
let mut file = MockFile::default();
file.expect_inner_write()
.once()
.with(eq(HELLO))
.returning(|buf| Ok(buf.len()));

let mut file = File::from_std(file);

let mut t = task::spawn(file.write(HELLO));

// In the fixed code, this returns Pending because spawn_blocking hasn't completed yet.
// This assertion fails in the old (broken) code, because it incorrectly returns Ready too early.
assert_pending!(t.poll());
// running spawn task
pool::run_one();
assert!(t.is_woken());
// after spawn task is run - in the sequential polling iteration, ˝the poll status is set to ready
assert_ready_ok!(t.poll());

let mut t = task::spawn(file.flush());
assert_ready_ok!(t.poll());
}
Loading