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

coop: fix flaky coop test #5074

Merged
merged 1 commit into from Oct 5, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
36 changes: 18 additions & 18 deletions tokio/tests/rt_common.rs
Expand Up @@ -1044,22 +1044,22 @@ rt_test! {
#[test]
fn coop() {
use std::task::Poll::Ready;
use tokio::sync::mpsc;

let rt = rt();

rt.block_on(async {
// Create a bunch of tasks
let mut tasks = (0..1_000).map(|_| {
tokio::spawn(async { })
}).collect::<Vec<_>>();
let (send, mut recv) = mpsc::unbounded_channel();

// Hope that all the tasks complete...
time::sleep(Duration::from_millis(100)).await;
// Send a bunch of messages.
for _ in 0..1_000 {
send.send(()).unwrap();
}

poll_fn(|cx| {
// At least one task should not be ready
for task in &mut tasks {
if Pin::new(task).poll(cx).is_pending() {
// At least one response should return pending.
for _ in 0..1_000 {
if recv.poll_recv(cx).is_pending() {
return Ready(());
}
}
Expand All @@ -1072,22 +1072,22 @@ rt_test! {
#[test]
fn coop_unconstrained() {
use std::task::Poll::Ready;
use tokio::sync::mpsc;

let rt = rt();

rt.block_on(async {
// Create a bunch of tasks
let mut tasks = (0..1_000).map(|_| {
tokio::spawn(async { })
}).collect::<Vec<_>>();
let (send, mut recv) = mpsc::unbounded_channel();

// Hope that all the tasks complete...
time::sleep(Duration::from_millis(100)).await;
// Send a bunch of messages.
for _ in 0..1_000 {
send.send(()).unwrap();
}

tokio::task::unconstrained(poll_fn(|cx| {
// All the tasks should be ready
for task in &mut tasks {
assert!(Pin::new(task).poll(cx).is_ready());
// All the responses should be ready.
for _ in 0..1_000 {
assert_eq!(recv.poll_recv(cx), Poll::Ready(Some(())));
}

Ready(())
Expand Down