Browse 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 4 years ago
parent
commit
8f33df9a67
1 changed files with 12 additions and 2 deletions
  1. 12
    2
      src/network/client.rs

+ 12
- 2
src/network/client.rs View File

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
     async fn send_packet(&mut self, call: CallData<PacketType, ErrorType>) {
151
     async fn send_packet(&mut self, call: CallData<PacketType, ErrorType>) {
146
         // Add an ID for the outgoing packet.
152
         // Add an ID for the outgoing packet.
147
         let id = self.free_ids.alloc();
153
         let id = self.free_ids.alloc();
317
 #[cfg(test)]
323
 #[cfg(test)]
318
 mod tests {
324
 mod tests {
319
     use super::*;
325
     use super::*;
320
-    use crate::network::test_utils::{panic_after, Pipe};
326
+    use crate::network::test_utils::{panic_after, Pipe, PipeError};
321
     use crate::network::Packet;
327
     use crate::network::Packet;
322
 
328
 
323
     type TestPayload = u32;
329
     type TestPayload = u32;
389
             // Client task.
395
             // Client task.
390
             let tasks = (
396
             let tasks = (
391
                 tokio::spawn(async move {
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
                 tokio::spawn(async move {
404
                 tokio::spawn(async move {
395
                     drop(pipe2);
405
                     drop(pipe2);

Loading…
Cancel
Save