mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-19 00:00:09 +02:00
rt: add task join coop test (#2345)
Add test verifying that joining on a task consumes the caller's budget.
This commit is contained in:
@@ -850,4 +850,32 @@ rt_test! {
|
||||
assert_eq!(buf, b"hello");
|
||||
tx.send(()).unwrap();
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn coop() {
|
||||
use std::task::Poll::Ready;
|
||||
|
||||
let mut rt = rt();
|
||||
|
||||
rt.block_on(async {
|
||||
// Create a bunch of tasks
|
||||
let mut tasks = (0..1_000).map(|_| {
|
||||
tokio::spawn(async { })
|
||||
}).collect::<Vec<_>>();
|
||||
|
||||
// Hope that all the tasks complete...
|
||||
time::delay_for(Duration::from_millis(100)).await;
|
||||
|
||||
poll_fn(|cx| {
|
||||
// At least one task should not be ready
|
||||
for task in &mut tasks {
|
||||
if Pin::new(task).poll(cx).is_pending() {
|
||||
return Ready(());
|
||||
}
|
||||
}
|
||||
|
||||
panic!("did not yield");
|
||||
}).await;
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user