Parcourir la source

Fix a RPC client test error when the connection is closed during sending.

We do not know anything about stream errors, so we cannot deduce whether
the stream was closed.
Mathias Gottschlag il y a 4 ans
Parent
révision
8f33df9a67
1 fichiers modifiés avec 12 ajouts et 2 suppressions
  1. 12
    2
      src/network/client.rs

+ 12
- 2
src/network/client.rs Voir le fichier

@@ -142,6 +142,12 @@ where
142 142
         }
143 143
     }
144 144
 
145
+    /// Sends a packet.
146
+    ///
147
+    /// # Errors
148
+    ///
149
+    /// If the connection is closed, the function does *not* return `RPCError::Closed`, but rather
150
+    /// returns the corresponding stream error.
145 151
     async fn send_packet(&mut self, call: CallData<PacketType, ErrorType>) {
146 152
         // Add an ID for the outgoing packet.
147 153
         let id = self.free_ids.alloc();
@@ -317,7 +323,7 @@ pub enum RPCError<StreamError> {
317 323
 #[cfg(test)]
318 324
 mod tests {
319 325
     use super::*;
320
-    use crate::network::test_utils::{panic_after, Pipe};
326
+    use crate::network::test_utils::{panic_after, Pipe, PipeError};
321 327
     use crate::network::Packet;
322 328
 
323 329
     type TestPayload = u32;
@@ -389,7 +395,11 @@ mod tests {
389 395
             // Client task.
390 396
             let tasks = (
391 397
                 tokio::spawn(async move {
392
-                    assert_eq!(client.call(42).await, Err(RPCError::Closed));
398
+                    let status = client.call(42).await;
399
+                    assert!(
400
+                        status == Err(RPCError::Closed)
401
+                            || status == Err(RPCError::Stream(PipeError::Closed))
402
+                    );
393 403
                 }),
394 404
                 tokio::spawn(async move {
395 405
                     drop(pipe2);

Loading…
Annuler
Enregistrer