Skip to content

Commit

Permalink
rt: add task join coop test (#2345)
Browse files Browse the repository at this point in the history
Add test verifying that joining on a task consumes the caller's budget.
  • Loading branch information
carllerche authored Mar 27, 2020
1 parent f2005a7 commit 11acfbb
Showing 1 changed file with 28 additions and 0 deletions.
28 changes: 28 additions & 0 deletions tokio/tests/rt_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
});
}
}

0 comments on commit 11acfbb

Please sign in to comment.