Explorar el Código

rpc/server/test: Stop all active connections when the server is stopped.

parazyd hace 2 años
padre
commit
882ef29351
Se han modificado 1 ficheros con 9 adiciones y 1 borrados
  1. 9 1
      src/rpc/server.rs

+ 9 - 1
src/rpc/server.rs

@@ -238,13 +238,21 @@ mod tests {
             drop(listener);
             drop(listener);
 
 
             let rpc_server = Arc::new(RpcServer { rpc_connections: Mutex::new(HashSet::new()) });
             let rpc_server = Arc::new(RpcServer { rpc_connections: Mutex::new(HashSet::new()) });
+            let rpc_server_ = rpc_server.clone();
 
 
             let server_task = StoppableTask::new();
             let server_task = StoppableTask::new();
             server_task.clone().start(
             server_task.clone().start(
                 listen_and_serve(endpoint.clone(), rpc_server.clone(), None, executor.clone()),
                 listen_and_serve(endpoint.clone(), rpc_server.clone(), None, executor.clone()),
                 |res| async move {
                 |res| async move {
                     match res {
                     match res {
-                        Ok(()) | Err(Error::RpcServerStopped) => {}
+                        Ok(()) | Err(Error::RpcServerStopped) => {
+                            eprintln!("Stopping connections");
+                            for (i, task) in rpc_server_.get_connections().await.iter().enumerate()
+                            {
+                                eprintln!("Stopping connection #{}", i);
+                                task.stop().await;
+                            }
+                        }
                         Err(e) => panic!("{}", e),
                         Err(e) => panic!("{}", e),
                     }
                     }
                 },
                 },