task: add tests for spawn_local in panic scenarios (#7694)

Signed-off-by: ADD-SP <[email protected]>
This commit is contained in:
Qi
2025-10-20 20:25:00 +08:00
committed by GitHub
parent acfdb87e2b
commit b8318fa172
4 changed files with 72 additions and 0 deletions
+18
View File
@@ -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 {});
}