mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-21 00:00:10 +02:00
task: add tests for spawn_local in panic scenarios (#7694)
Signed-off-by: ADD-SP <[email protected]>
This commit is contained in:
@@ -438,6 +438,24 @@ async fn duplicate_keys_drop() {
|
||||
mod spawn_local {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"
|
||||
)]
|
||||
fn panic_outside_any_runtime() {
|
||||
let mut map = JoinMap::new();
|
||||
map.spawn_local((), async {});
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
#[should_panic(
|
||||
expected = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"
|
||||
)]
|
||||
async fn panic_in_multi_thread_runtime() {
|
||||
let mut map = JoinMap::new();
|
||||
map.spawn_local((), async {});
|
||||
}
|
||||
|
||||
#[cfg(tokio_unstable)]
|
||||
mod local_runtime {
|
||||
use super::*;
|
||||
|
||||
@@ -359,3 +359,21 @@ async fn test_join_queue_try_join_next_with_id_disabled_coop() {
|
||||
assert_eq!(count, TASK_NUM);
|
||||
assert_eq!(joined, spawned);
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"
|
||||
)]
|
||||
fn spawn_local_panic_outside_any_runtime() {
|
||||
let mut queue = JoinQueue::new();
|
||||
queue.spawn_local(async {});
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
#[should_panic(
|
||||
expected = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"
|
||||
)]
|
||||
async fn spawn_local_panic_in_multi_thread_runtime() {
|
||||
let mut queue = JoinQueue::new();
|
||||
queue.spawn_local(async {});
|
||||
}
|
||||
|
||||
@@ -213,6 +213,24 @@ mod spawn {
|
||||
mod spawn_local {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"
|
||||
)]
|
||||
fn panic_outside_any_runtime() {
|
||||
let tracker = TaskTracker::new();
|
||||
tracker.spawn_local(async {});
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
#[should_panic(
|
||||
expected = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"
|
||||
)]
|
||||
async fn panic_in_multi_thread_runtime() {
|
||||
let tracker = TaskTracker::new();
|
||||
tracker.spawn_local(async {});
|
||||
}
|
||||
|
||||
/// Spawn several tasks, and then close the [`TaskTracker`].
|
||||
#[tokio::test(flavor = "local")]
|
||||
async fn spawn_then_close() {
|
||||
|
||||
@@ -407,6 +407,24 @@ async fn try_join_next_with_id() {
|
||||
mod spawn_local {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
#[should_panic(
|
||||
expected = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"
|
||||
)]
|
||||
fn panic_outside_any_runtime() {
|
||||
let mut set = JoinSet::new();
|
||||
set.spawn_local(async {});
|
||||
}
|
||||
|
||||
#[tokio::test(flavor = "multi_thread")]
|
||||
#[should_panic(
|
||||
expected = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"
|
||||
)]
|
||||
async fn panic_in_multi_thread_runtime() {
|
||||
let mut set = JoinSet::new();
|
||||
set.spawn_local(async {});
|
||||
}
|
||||
|
||||
#[cfg(tokio_unstable)]
|
||||
mod local_runtime {
|
||||
use super::*;
|
||||
|
||||
Reference in New Issue
Block a user