From 5ff6010a1395e07e95e858cf2ce00c48fedb2fb7 Mon Sep 17 00:00:00 2001 From: "zero.qn" Date: Fri, 3 Jul 2020 16:07:59 +0800 Subject: [PATCH] change(trust_metric_test): check running status before rpc and broadcast --- tests/trust_metric_all/node/client_node.rs | 21 +++++++++++++------ .../node/full_node/default_start.rs | 2 -- 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tests/trust_metric_all/node/client_node.rs b/tests/trust_metric_all/node/client_node.rs index 0471d5f6b..1bbf37f9d 100644 --- a/tests/trust_metric_all/node/client_node.rs +++ b/tests/trust_metric_all/node/client_node.rs @@ -138,14 +138,24 @@ impl ClientNode { .is_some() } + pub fn connected_session(&self, addr: &Address) -> Option { + if !self.connected() { + None + } else { + self.network + .diagnostic + .session_by_chain(addr) + .map(|sid| sid.value()) + } + } + pub async fn broadcast(&self, endpoint: &str, msg: M) -> ClientResult<()> { - let diagnostic = &self.network.diagnostic; - let sid = match diagnostic.session_by_chain(&self.remote_chain_addr) { + let sid = match self.connected_session(&self.remote_chain_addr) { Some(sid) => sid, None => return Err(ClientNodeError::NotConnected), }; - let ctx = Context::new().with_value::("session_id", sid.value()); + let ctx = Context::new().with_value::("session_id", sid); let users = vec![self.remote_chain_addr.clone()]; if let Err(e) = self .users_cast::(ctx, endpoint, users, msg, Priority::High) @@ -172,13 +182,12 @@ impl ClientNode { endpoint: &str, msg: M, ) -> ClientResult { - let diagnostic = &self.network.diagnostic; - let sid = match diagnostic.session_by_chain(&self.remote_chain_addr) { + let sid = match self.connected_session(&self.remote_chain_addr) { Some(sid) => sid, None => return Err(ClientNodeError::NotConnected), }; - let ctx = Context::new().with_value::("session_id", sid.value()); + let ctx = Context::new().with_value::("session_id", sid); match self.call::(ctx, endpoint, msg, Priority::High).await { Ok(resp) => Ok(resp), Err(e) diff --git a/tests/trust_metric_all/node/full_node/default_start.rs b/tests/trust_metric_all/node/full_node/default_start.rs index fc62d8423..60857487e 100644 --- a/tests/trust_metric_all/node/full_node/default_start.rs +++ b/tests/trust_metric_all/node/full_node/default_start.rs @@ -8,7 +8,6 @@ use super::{common, config::Config, consts, error::MainError, memory_db::MemoryD use std::collections::HashMap; use std::convert::TryFrom; use std::sync::Arc; -use std::panic; use bytes::Bytes; use futures::lock::Mutex; @@ -485,7 +484,6 @@ pub async fn start( }); exec_demon.run().await; - let _ = consensus_handle.await; let _ = running;