-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Add new tests for JoinSet, JoinMap, TaskTracer and LocalRuntime #7609
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
base: master
Are you sure you want to change the base?
Conversation
Hi @FrancescoV1985 , any update on this PR? |
|
There was a problem hiding this 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?
tokio/tests/task_join_set.rs
Outdated
set.spawn_local_on(async move { *rc }, &local); | ||
} | ||
|
||
assert!(set.try_join_next().is_none()); |
There was a problem hiding this comment.
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.
tokio/tests/task_join_set.rs
Outdated
// 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() { |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
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...
I committed the tests for TaskTracker. I still need to add comments and double check. I will pm you for some clarifications.. |
There was a problem hiding this 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.
There was a problem hiding this comment.
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 {
}
}
There was a problem hiding this comment.
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
There was a problem hiding this 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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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() { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
async fn shutdown_spawn_local_localset() { | |
async fn spawn_then_shutdown() { |
// Shutdown a `JoinSet` that was populated with `spawn_local` | ||
// must abort all still-running tasks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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`]. |
// Dropping a `JoinSet` that was populated with `spawn_local` | ||
// must abort all still-running tasks. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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`]. |
// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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. |
// 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. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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. |
// Calling `JoinSet::shutdown` on a set whose tasks were queued with | ||
// `spawn_local_on` must abort all of them once the `LocalSet` is driven. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
// 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`]. |
Fixes: #7562
Motivation
Improve the test coverage of task containers on LocalRuntime
Solution
Added new tests for JoinSet, JoinMap, TaskTracer