Skip to content

Commit 3ee6af2

Browse files
committed
io: add a cooperative case for copy_bidirectional
Signed-off-by: hi-rustin <[email protected]>
1 parent 54fb72c commit 3ee6af2

File tree

1 file changed

+25
-0
lines changed

1 file changed

+25
-0
lines changed

tokio/tests/io_copy_bidirectional.rs

+25
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,28 @@ async fn immediate_exit_on_read_error() {
138138

139139
assert!(copy_bidirectional(&mut a, &mut b).await.is_err());
140140
}
141+
142+
#[tokio::test]
143+
async fn copy_bidirectional_is_cooperative() {
144+
tokio::select! {
145+
biased;
146+
_ = async {
147+
loop {
148+
let payload = b"here, take this";
149+
150+
let mut a = tokio_test::io::Builder::new()
151+
.read(payload)
152+
.write(payload)
153+
.build();
154+
155+
let mut b = tokio_test::io::Builder::new()
156+
.read(payload)
157+
.write(payload)
158+
.build();
159+
160+
let _ = copy_bidirectional(&mut a, &mut b).await;
161+
}
162+
} => {},
163+
_ = tokio::task::yield_now() => {}
164+
}
165+
}

0 commit comments

Comments
 (0)