diff --git a/tokio/tests/rt_local.rs b/tokio/tests/rt_local.rs index 4eb88d48a4d..3393482c348 100644 --- a/tokio/tests/rt_local.rs +++ b/tokio/tests/rt_local.rs @@ -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()