You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@dubbo.apache.org by GitBox <gi...@apache.org> on 2022/12/06 09:54:42 UTC

[GitHub] [dubbo-rust] tuchg commented on a diff in pull request #83: Rpc context implementation #58

tuchg commented on code in PR #83:
URL: https://github.com/apache/dubbo-rust/pull/83#discussion_r1040737095


##########
dubbo/src/context.rs:
##########
@@ -96,16 +96,17 @@ mod tests {
 
         let mut handles = Vec::with_capacity(10);
 
-        for i in 0..10 {
+        for i in 0..=10 {
             handles.push(rt.spawn(async move {
-                let mut attachments = RpcContext::current().attachments;
-                attachments.insert("key1".into(), Arc::new(format!("data-{i}")));
-
-                if i == 10 {
-                    attachments.insert("key2".into(), Arc::new(2));
-                    assert_eq!(attachments.len(), 2);
-                } else {
-                    assert_eq!(attachments.len(), 1);
+                let attachments = RpcContext::get_attachments();
+                match attachments {
+                    Some(at) => {
+                        let mut attachments = at.lock().unwrap();
+                        attachments.insert("key1".into(), Arc::new(format!("data-{i}")));
+

Review Comment:
   或许可以试着在这里调用下 tokio 的 sleep,触发了协程调度后再来验证结果?
   而且最好是尝试再次 `let attachments = RpcContext::get_attachments();`去验证结果,直接复用引用会有问题



##########
dubbo/src/context.rs:
##########
@@ -96,16 +96,17 @@ mod tests {
 
         let mut handles = Vec::with_capacity(10);
 
-        for i in 0..10 {
+        for i in 0..=10 {
             handles.push(rt.spawn(async move {
-                let mut attachments = RpcContext::current().attachments;
-                attachments.insert("key1".into(), Arc::new(format!("data-{i}")));
-
-                if i == 10 {
-                    attachments.insert("key2".into(), Arc::new(2));
-                    assert_eq!(attachments.len(), 2);
-                } else {
-                    assert_eq!(attachments.len(), 1);
+                let attachments = RpcContext::get_attachments();
+                match attachments {

Review Comment:
   可以尝试使用 `if let Some()`简化 match



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
users@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscribe@dubbo.apache.org
For additional commands, e-mail: notifications-help@dubbo.apache.org