MCPcopy Create free account
hub / github.com/apache/dubbo-rust / context_with_thread_local

Function context_with_thread_local

dubbo/src/context.rs:75–105  ·  view source on GitHub ↗
()

Source from the content-addressed store, hash-verified

73
74 #[test]
75 fn context_with_thread_local() {
76 let rt = tokio::runtime::Builder::new_multi_thread()
77 .max_blocking_threads(2)
78 .enable_all()
79 .build()
80 .unwrap();
81
82 let mut handles = Vec::with_capacity(10);
83
84 for i in 0..=10 {
85 handles.push(rt.spawn(async move {
86 if let Some(attachments) = RpcContext::get_attachments() {
87 let mut attachments = attachments.lock().unwrap();
88 attachments.insert("key1".into(), Value::from(format!("data-{i}")));
89
90 assert!(attachments.len() > 0);
91 };
92
93 time::sleep(Duration::from_millis(1000)).await;
94
95 if let Some(attachments) = RpcContext::get_attachments() {
96 let attachments = attachments.lock().unwrap();
97 assert!(attachments.len() > 0);
98 };
99 }));
100 }
101
102 for handle in handles {
103 rt.block_on(handle).unwrap();
104 }
105 }
106}

Callers

nothing calls this directly

Calls 2

insertMethod · 0.80
buildMethod · 0.45

Tested by

no test coverage detected