fn context_with_thread_local()

in dubbo/src/context.rs [75:105]


    fn context_with_thread_local() {
        let rt = tokio::runtime::Builder::new_multi_thread()
            .max_blocking_threads(2)
            .enable_all()
            .build()
            .unwrap();

        let mut handles = Vec::with_capacity(10);

        for i in 0..=10 {
            handles.push(rt.spawn(async move {
                if let Some(attachments) = RpcContext::get_attachments() {
                    let mut attachments = attachments.lock().unwrap();
                    attachments.insert("key1".into(), Value::from(format!("data-{i}")));

                    assert!(attachments.len() > 0);
                };

                time::sleep(Duration::from_millis(1000)).await;

                if let Some(attachments) = RpcContext::get_attachments() {
                    let attachments = attachments.lock().unwrap();
                    assert!(attachments.len() > 0);
                };
            }));
        }

        for handle in handles {
            rt.block_on(handle).unwrap();
        }
    }