Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix spurious failure in rt_common coop test #4489

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 24 additions & 8 deletions tokio/tests/rt_common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -989,20 +989,30 @@ rt_test! {
tx.send(()).unwrap();
}


// Should be above initial coop budget, currently 128.
const COOP_NUM_TASKS: usize = 1000;

#[test]
fn coop() {
use std::task::Poll::Ready;

let rt = rt();

rt.block_on(async {
let (tx, mut rx) = tokio::sync::mpsc::channel(COOP_NUM_TASKS);

// Create a bunch of tasks
let mut tasks = (0..1_000).map(|_| {
tokio::spawn(async { })
let mut tasks = (0..COOP_NUM_TASKS).map(|_| {
let tx = tx.clone();
tokio::spawn(async move{
tx.send(()).await.expect("send");
})
}).collect::<Vec<_>>();

// Hope that all the tasks complete...
time::sleep(Duration::from_millis(100)).await;
for _ in 0..COOP_NUM_TASKS {
rx.recv().await;
}

poll_fn(|cx| {
// At least one task should not be ready
Expand All @@ -1024,13 +1034,19 @@ rt_test! {
let rt = rt();

rt.block_on(async {
let (tx, mut rx) = tokio::sync::mpsc::channel(COOP_NUM_TASKS);

// Create a bunch of tasks
let mut tasks = (0..1_000).map(|_| {
tokio::spawn(async { })
let mut tasks = (0..COOP_NUM_TASKS).map(|_| {
let tx = tx.clone();
tokio::spawn(async move{
tx.send(()).await.expect("send");
})
}).collect::<Vec<_>>();

// Hope that all the tasks complete...
time::sleep(Duration::from_millis(100)).await;
for _ in 0..COOP_NUM_TASKS {
rx.recv().await;
}

tokio::task::unconstrained(poll_fn(|cx| {
// All the tasks should be ready
Expand Down