io: rewrite immediate_exit_on_error test to use io::Mock (#4984)

This commit is contained in:
Piotr 2022-09-08 11:39:06 +02:00 committed by GitHub
parent dfdb550cd4
commit 3966acf966
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -111,18 +111,30 @@ async fn blocking_one_side_does_not_block_other() {
} }
#[tokio::test] #[tokio::test]
async fn immediate_exit_on_error() { async fn immediate_exit_on_write_error() {
symmetric(|handle, mut a, mut b| async move { let payload = b"here, take this";
block_write(&mut a).await; let error = || io::Error::new(io::ErrorKind::Other, "no thanks!");
// Fill up the b->copy->a path. We expect that this will _not_ drain let mut a = tokio_test::io::Builder::new()
// before we exit the copy task. .read(payload)
let _bytes_written = block_write(&mut b).await; .write_error(error())
.build();
// Drop b. We should not wait for a to consume the data buffered in the let mut b = tokio_test::io::Builder::new()
// copy loop, since b will be failing writes. .read(payload)
drop(b); .write_error(error())
assert!(handle.await.unwrap().is_err()); .build();
})
.await assert!(copy_bidirectional(&mut a, &mut b).await.is_err());
}
#[tokio::test]
async fn immediate_exit_on_read_error() {
let error = || io::Error::new(io::ErrorKind::Other, "got nothing!");
let mut a = tokio_test::io::Builder::new().read_error(error()).build();
let mut b = tokio_test::io::Builder::new().read_error(error()).build();
assert!(copy_bidirectional(&mut a, &mut b).await.is_err());
} }