runtime: add tests for spawn local on multi and current runtimes (#7687)

This commit is contained in:
Mattia Pitossi
2025-10-15 22:09:46 +03:00
committed by GitHub
parent 2137f7d953
commit d23a838732
+22
View File
@@ -111,6 +111,28 @@ fn test_spawn_local_from_guard_other_thread() {
spawn_local(async {});
}
#[test]
#[should_panic = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"]
fn test_spawn_local_in_current_thread_runtime() {
let rt = tokio::runtime::Builder::new_current_thread()
.build()
.unwrap();
rt.block_on(async move {
spawn_local(async {});
})
}
#[test]
#[should_panic = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"]
fn test_spawn_local_in_multi_thread_runtime() {
let rt = tokio::runtime::Builder::new_multi_thread().build().unwrap();
rt.block_on(async move {
spawn_local(async {});
})
}
fn rt() -> tokio::runtime::LocalRuntime {
tokio::runtime::Builder::new_current_thread()
.enable_all()