Skip to content
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

tokio_test::io::Mock does not read actions from handle when used as writer #5813

Closed
pbrenna opened this issue Jun 23, 2023 · 0 comments · Fixed by #5814
Closed

tokio_test::io::Mock does not read actions from handle when used as writer #5813

pbrenna opened this issue Jun 23, 2023 · 0 comments · Fixed by #5814
Labels
A-tokio-test Area: The tokio-test crate C-bug Category: This is a bug.

Comments

@pbrenna
Copy link
Contributor

pbrenna commented Jun 23, 2023

Version

├── tokio v1.28.2
│   └── tokio-macros v2.1.0 (proc-macro)
└── tokio-test v0.4.2
    ├── tokio v1.28.2 (*)
    └── tokio-stream v0.1.14
        └── tokio v1.28.2 (*)

Platform
Linux lenovo-arch 6.3.8-arch1-1 #1 SMP PREEMPT_DYNAMIC Wed, 14 Jun 2023 20:10:31 +0000 x86_64 GNU/Linux

[dependencies]
tokio = {version = "1.28.2", features = ["macros", "rt-multi-thread", "io-util", "rt"]}
tokio-test = "0.4.2"

Description

use tokio_test::io::Builder;

use tokio::io::{AsyncReadExt, AsyncWriteExt};
#[tokio::main]
async fn main() {
    let mut wr = Builder::new().write(b"hello").build();
    println!("{:?}", AsyncWriteExt::write(&mut wr, b"hello").await);

    let (mut wr, mut wr_h) = Builder::new().build_with_handle();
    wr_h.write(b"hello");
    println!("{:?}", AsyncWriteExt::write(&mut wr, b"hello").await);

    let (mut wr, mut wr_h) = Builder::new().build_with_handle();
    wr_h.read(b"world");
    let mut buf = vec![0; 8];
    println!("{:?}", AsyncReadExt::read(&mut wr, &mut buf).await);
}

Expected output:

Ok(5)
Ok(5)
Ok(5)

Actual output:

Ok(5)
Err(Kind(BrokenPipe))
Ok(5)

Additional notes

tokio/tokio-test/src/io.rs

Lines 422 to 425 in 2e62374

// TODO: Is this correct?
if !self.inner.actions.is_empty() {
return Poll::Pending;
}

I suspect this is not correct
EDIT: I suspect instead that this is fine, but self.inner.poll_action should be called before self.inner.write. Working on PR.

@pbrenna pbrenna added A-tokio Area: The main tokio crate C-bug Category: This is a bug. labels Jun 23, 2023
@pbrenna pbrenna changed the title tokio_test::ioMock does not read actions from handle tokio_test::ioMock does not read actions from handle when used as writer Jun 23, 2023
@pbrenna pbrenna changed the title tokio_test::ioMock does not read actions from handle when used as writer tokio_test::io::Mock does not read actions from handle when used as writer Jun 23, 2023
pbrenna pushed a commit to pbrenna/tokio that referenced this issue Jun 23, 2023
pbrenna pushed a commit to pbrenna/tokio that referenced this issue Jun 23, 2023
pbrenna pushed a commit to pbrenna/tokio that referenced this issue Jun 23, 2023
pbrenna pushed a commit to pbrenna/tokio that referenced this issue Jun 23, 2023
This covers the case when a Mock is created without
any action, for use with an Handle.

Refs: tokio-rs#5813
pbrenna pushed a commit to pbrenna/tokio that referenced this issue Jun 23, 2023
When creating a tokio_test::io::Mock with no actions,
bew actions were never fetched from the mock Handle.
This change fetches an action from the Handle, if present.

Fixes: tokio-rs#5813
pbrenna pushed a commit to pbrenna/tokio that referenced this issue Jun 23, 2023
This covers the case when a Mock is created without
any action, for use with an Handle.

Refs: tokio-rs#5813
pbrenna pushed a commit to pbrenna/tokio that referenced this issue Jun 23, 2023
When creating a tokio_test::io::Mock with no actions,
bew actions were never fetched from the mock Handle.
This change fetches an action from the Handle, if present.

Fixes: tokio-rs#5813
pbrenna pushed a commit to pbrenna/tokio that referenced this issue Jun 23, 2023
This covers the case when a Mock is created without
any action, for use with an Handle.

Refs: tokio-rs#5813
pbrenna pushed a commit to pbrenna/tokio that referenced this issue Jun 23, 2023
When creating a tokio_test::io::Mock with no actions,
bew actions were never fetched from the mock Handle.
This change fetches an action from the Handle, if present.

Fixes: tokio-rs#5813
pbrenna pushed a commit to pbrenna/tokio that referenced this issue Jun 23, 2023
This covers the case when a Mock is created without
any action, for use with an Handle.

Refs: tokio-rs#5813
pbrenna pushed a commit to pbrenna/tokio that referenced this issue Jun 23, 2023
When creating a tokio_test::io::Mock with no actions,
bew actions were never fetched from the mock Handle.
This change fetches an action from the Handle, if present.

Fixes: tokio-rs#5813
@Darksonn Darksonn added A-tokio-test Area: The tokio-test crate and removed A-tokio Area: The main tokio crate labels Jul 3, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio-test Area: The tokio-test crate C-bug Category: This is a bug.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants