File tree Expand file tree Collapse file tree 4 files changed +72
-0
lines changed Expand file tree Collapse file tree 4 files changed +72
-0
lines changed Original file line number Diff line number Diff line change @@ -438,6 +438,24 @@ async fn duplicate_keys_drop() {
438438mod spawn_local {
439439 use super :: * ;
440440
441+ #[ test]
442+ #[ should_panic(
443+ expected = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"
444+ ) ]
445+ fn panic_outside_any_runtime ( ) {
446+ let mut map = JoinMap :: new ( ) ;
447+ map. spawn_local ( ( ) , async { } ) ;
448+ }
449+
450+ #[ tokio:: test( flavor = "multi_thread" ) ]
451+ #[ should_panic(
452+ expected = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"
453+ ) ]
454+ async fn panic_in_multi_thread_runtime ( ) {
455+ let mut map = JoinMap :: new ( ) ;
456+ map. spawn_local ( ( ) , async { } ) ;
457+ }
458+
441459 #[ cfg( tokio_unstable) ]
442460 mod local_runtime {
443461 use super :: * ;
Original file line number Diff line number Diff line change @@ -359,3 +359,21 @@ async fn test_join_queue_try_join_next_with_id_disabled_coop() {
359359 assert_eq ! ( count, TASK_NUM ) ;
360360 assert_eq ! ( joined, spawned) ;
361361}
362+
363+ #[ test]
364+ #[ should_panic(
365+ expected = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"
366+ ) ]
367+ fn spawn_local_panic_outside_any_runtime ( ) {
368+ let mut queue = JoinQueue :: new ( ) ;
369+ queue. spawn_local ( async { } ) ;
370+ }
371+
372+ #[ tokio:: test( flavor = "multi_thread" ) ]
373+ #[ should_panic(
374+ expected = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"
375+ ) ]
376+ async fn spawn_local_panic_in_multi_thread_runtime ( ) {
377+ let mut queue = JoinQueue :: new ( ) ;
378+ queue. spawn_local ( async { } ) ;
379+ }
Original file line number Diff line number Diff line change @@ -213,6 +213,24 @@ mod spawn {
213213mod spawn_local {
214214 use super :: * ;
215215
216+ #[ test]
217+ #[ should_panic(
218+ expected = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"
219+ ) ]
220+ fn panic_outside_any_runtime ( ) {
221+ let tracker = TaskTracker :: new ( ) ;
222+ tracker. spawn_local ( async { } ) ;
223+ }
224+
225+ #[ tokio:: test( flavor = "multi_thread" ) ]
226+ #[ should_panic(
227+ expected = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"
228+ ) ]
229+ async fn panic_in_multi_thread_runtime ( ) {
230+ let tracker = TaskTracker :: new ( ) ;
231+ tracker. spawn_local ( async { } ) ;
232+ }
233+
216234 /// Spawn several tasks, and then close the [`TaskTracker`].
217235 #[ tokio:: test( flavor = "local" ) ]
218236 async fn spawn_then_close ( ) {
Original file line number Diff line number Diff line change @@ -407,6 +407,24 @@ async fn try_join_next_with_id() {
407407mod spawn_local {
408408 use super :: * ;
409409
410+ #[ test]
411+ #[ should_panic(
412+ expected = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"
413+ ) ]
414+ fn panic_outside_any_runtime ( ) {
415+ let mut set = JoinSet :: new ( ) ;
416+ set. spawn_local ( async { } ) ;
417+ }
418+
419+ #[ tokio:: test( flavor = "multi_thread" ) ]
420+ #[ should_panic(
421+ expected = "`spawn_local` called from outside of a `task::LocalSet` or `runtime::LocalRuntime`"
422+ ) ]
423+ async fn panic_in_multi_thread_runtime ( ) {
424+ let mut set = JoinSet :: new ( ) ;
425+ set. spawn_local ( async { } ) ;
426+ }
427+
410428 #[ cfg( tokio_unstable) ]
411429 mod local_runtime {
412430 use super :: * ;
You can’t perform that action at this time.
0 commit comments