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
@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?

Copy link
Author

Choose a reason for hiding this comment

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

The difference is that in spawn_local_on_local_runtime I am using LocalSet inside LocalRunTime as the comment says "// Drive a LocalSet on top of a LocalRuntime ". I leave it to you whether to consider one of them redundant...

@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..

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.

Please sync changes from the base branch to fix the CI failures.

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

@ADD-SP ADD-SP Oct 8, 2025

Choose a reason for hiding this comment

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

Currently, the test combinations looks complicated and hard to understand.

  • spawn_local_local_runtime
  • spawn_local_on_local_runtime
  • shutdown_spawn_local_local_runtime
  • drop_spawn_local_local_runtime
  • ......

Could you try to make it more clear? For example, grouping tests using mod.

mod spawn_local {
    mod local_runtime {
    }

    mod local_set {
    }
}

mod spawn_local_on {
    mod local_runtime {
    }

    mod local_set {
    }
}

Copy link
Author

Choose a reason for hiding this comment

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

Concerning TaskTracker, I am considering to simplify some tests...Please be patient

@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 Oct 8, 2025
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.

Since the mod name has already indicated the scope, we can improve the test name, also change the comments.

Feel free to re-write the suggested changes.

// `JoinSet::spawn_local`, and wait for every task to finish.
#[cfg(tokio_unstable)]
#[test]
fn spawn_local_local_runtime() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fn spawn_local_local_runtime() {
fn spawn_then_join_next() {

// inserted with `JoinSet::spawn_local`.
#[cfg(tokio_unstable)]
#[test]
fn shutdown_spawn_local_local_runtime() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fn shutdown_spawn_local_local_runtime() {
fn spawn_then_shutdown() {

// added with `JoinSet::spawn_local`.
#[cfg(tokio_unstable)]
#[test]
fn drop_spawn_local_local_runtime() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
fn drop_spawn_local_local_runtime() {
fn spawn_then_drop() {

// Every task is spawned with `spawn_local` **inside** the `LocalSet`
// that is currently running.
#[tokio::test(flavor = "current_thread")]
async fn spawn_local_running_localset() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
async fn spawn_local_running_localset() {
async fn spawn_then_join_next() {

// Shutdown a `JoinSet` that was populated with `spawn_local`
// must abort all still-running tasks.
#[tokio::test(flavor = "current_thread")]
async fn shutdown_spawn_local_localset() {
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
async fn shutdown_spawn_local_localset() {
async fn spawn_then_shutdown() {

Comment on lines +500 to +501
// Shutdown a `JoinSet` that was populated with `spawn_local`
// must abort all still-running tasks.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Shutdown a `JoinSet` that was populated with `spawn_local`
// must abort all still-running tasks.
/// Spawn several pending-forever tasks, and then shutdown the [`JoinSet`].

Comment on lines +523 to +524
// Dropping a `JoinSet` that was populated with `spawn_local`
// must abort all still-running tasks.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Dropping a `JoinSet` that was populated with `spawn_local`
// must abort all still-running tasks.
/// Spawn several pending-forever tasks, and then drop the [`JoinSet`].

Comment on lines +553 to +555
// Drive a `LocalSet` on top of a `LocalRuntime` and verify that tasks
// queued with `JoinSet::spawn_local_on` run to completion only after
// the `LocalSet` starts.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Drive a `LocalSet` on top of a `LocalRuntime` and verify that tasks
// queued with `JoinSet::spawn_local_on` run to completion only after
// the `LocalSet` starts.
/// Spawn several tasks, and then join all tasks.

Comment on lines +581 to +583
// JoinSet::spawn_local on a LocalSet.
// Tasks are queued with `spawn_local_on` **before** the `LocalSet` is
// running, then executed once the `LocalSet` is started.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// JoinSet::spawn_local on a LocalSet.
// Tasks are queued with `spawn_local_on` **before** the `LocalSet` is
// running, then executed once the `LocalSet` is started.
/// Spawn several tasks, and then join all tasks.

Comment on lines +600 to +601
// Calling `JoinSet::shutdown` on a set whose tasks were queued with
// `spawn_local_on` must abort all of them once the `LocalSet` is driven.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
// Calling `JoinSet::shutdown` on a set whose tasks were queued with
// `spawn_local_on` must abort all of them once the `LocalSet` is driven.
/// Spawn several pending-forever tasks, and then shutdown the [`JoinSet`].

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