1 #![cfg(feature = "full")] 2 3 tokio::task_local! { 4 static REQ_ID: u32; 5 pub static FOO: bool; 6 } 7 8 #[tokio::test(flavor = "multi_thread")] local()9async fn local() { 10 let j1 = tokio::spawn(REQ_ID.scope(1, async move { 11 assert_eq!(REQ_ID.get(), 1); 12 assert_eq!(REQ_ID.get(), 1); 13 })); 14 15 let j2 = tokio::spawn(REQ_ID.scope(2, async move { 16 REQ_ID.with(|v| { 17 assert_eq!(REQ_ID.get(), 2); 18 assert_eq!(*v, 2); 19 }); 20 21 tokio::time::sleep(std::time::Duration::from_millis(10)).await; 22 23 assert_eq!(REQ_ID.get(), 2); 24 })); 25 26 let j3 = tokio::spawn(FOO.scope(true, async move { 27 assert!(FOO.get()); 28 })); 29 30 j1.await.unwrap(); 31 j2.await.unwrap(); 32 j3.await.unwrap(); 33 } 34