mirror of
https://github.com/tokio-rs/tokio.git
synced 2026-08-24 00:00:11 +02:00
runtime: add tests for spawn local on multi and current runtimes (#7687)
This commit is contained in:
@@ -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()
|
||||
|
||||
Reference in New Issue
Block a user