Skip to content

Conversation

FrancescoV1985
Copy link

Fixes: #7562

Motivation

Improve the test coverage of task containers on LocalRuntime

Solution

Added new tests for JoinSet, JoinMap, TaskTracer

@ADD-SP ADD-SP added A-tokio-util Area: The tokio-util crate C-maintenance Category: PRs that clean code up or issues documenting cleanup. A-tokio Area: The main tokio crate M-task Module: tokio/task labels Sep 15, 2025
}

// Dropping a `JoinSet` created inside a **LocalRuntime**
// must abort every still-running `!Send` task that was
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

must abort every still-running !Send task that was

Does Send or not matter?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No, it doesn't. I will modify the comment removing " !Send "

@ADD-SP ADD-SP added the S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author. label Sep 15, 2025
@ADD-SP
Copy link
Member

ADD-SP commented Sep 25, 2025

Hi @FrancescoV1985 , any update on this PR?

@FrancescoV1985
Copy link
Author

FrancescoV1985 commented Sep 25, 2025

Hi @FrancescoV1985 , any update on this PR?
Hi @ADD-SP
I have updated the code (see pm on discord)

Copy link
Member

@ADD-SP ADD-SP left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you try to reduce the duplicated code from test code? Also, Are the tests for TaskTracker in the scope of this PR?

set.spawn_local_on(async move { *rc }, &local);
}

assert!(set.try_join_next().is_none());
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually, since we are using the single thread runtime and there is no yield point here, the set.try_join_next() is always None, we should rewrite this test.

// Tasks are queued with `spawn_local_on` **before** the `LocalSet` is
// running, then executed once the `LocalSet` is started.
#[tokio::test(flavor = "current_thread")]
async fn spawn_local_on_on_started_localset() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What's the difference between this test and spawn_local_on_local_runtime?

Comment on lines +679 to +686
for _ in 0..N {
let (tx, rx) = oneshot::channel::<()>();
receivers.push(rx);
set.spawn_local(async move {
pending::<()>().await;
drop(tx);
});
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There are many duplicated code like this, could you try to improve this de-dup it?

Comment on lines +692 to +697
for rx in receivers {
assert!(
rx.await.is_err(),
"the task should have been aborted and the sender dropped"
);
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you try to de-dup this kind of code?

@FrancescoV1985
Copy link
Author

FrancescoV1985 commented Sep 26, 2025

Could you try to reduce the duplicated code from test code? Also, Are the tests for TaskTracker in the scope of this PR?

I committed the tests for TaskTracker. I still need to add comments and double check. I will pm you for some clarifications..

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-tokio Area: The main tokio crate A-tokio-util Area: The tokio-util crate C-maintenance Category: PRs that clean code up or issues documenting cleanup. M-task Module: tokio/task S-waiting-on-author Status: awaiting some action (such as code changes) from the PR or issue author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Improve the test coverage of task containers on LocalRuntime
2 participants