Skip to content

Commit

Permalink
io: add a cooperative case for copy_bidirectional
Browse files Browse the repository at this point in the history
Signed-off-by: hi-rustin <rustin.liu@gmail.com>
  • Loading branch information
Rustin170506 committed Jan 5, 2024
1 parent 818f063 commit e574356
Showing 1 changed file with 25 additions and 0 deletions.
25 changes: 25 additions & 0 deletions tokio/tests/io_copy_bidirectional.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,3 +138,28 @@ async fn immediate_exit_on_read_error() {

assert!(copy_bidirectional(&mut a, &mut b).await.is_err());
}

#[tokio::test]
async fn copy_bidirectional_is_cooperative() {
tokio::select! {
biased;
_ = async {
loop {
let payload = b"here, take this";

let mut a = tokio_test::io::Builder::new()
.read(payload)
.write(payload)
.build();

let mut b = tokio_test::io::Builder::new()
.read(payload)
.write(payload)
.build();

let _ = copy_bidirectional(&mut a, &mut b).await;
}
} => {},
_ = tokio::task::yield_now() => {}
}
}

0 comments on commit e574356

Please sign in to comment.