Skip to content

Commit

Permalink
change(trust_metric_test): check running status before rpc and broadcast
Browse files Browse the repository at this point in the history
  • Loading branch information
zeroqn committed Jul 3, 2020
1 parent 3072304 commit 5ff6010
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 15 additions & 6 deletions tests/trust_metric_all/node/client_node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,14 +138,24 @@ impl ClientNode {
.is_some()
}

pub fn connected_session(&self, addr: &Address) -> Option<usize> {
if !self.connected() {
None
} else {
self.network
.diagnostic
.session_by_chain(addr)
.map(|sid| sid.value())
}
}

pub async fn broadcast<M: MessageCodec>(&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::<usize>("session_id", sid.value());
let ctx = Context::new().with_value::<usize>("session_id", sid);
let users = vec![self.remote_chain_addr.clone()];
if let Err(e) = self
.users_cast::<M>(ctx, endpoint, users, msg, Priority::High)
Expand All @@ -172,13 +182,12 @@ impl ClientNode {
endpoint: &str,
msg: M,
) -> ClientResult<R> {
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::<usize>("session_id", sid.value());
let ctx = Context::new().with_value::<usize>("session_id", sid);
match self.call::<M, R>(ctx, endpoint, msg, Priority::High).await {
Ok(resp) => Ok(resp),
Err(e)
Expand Down
2 changes: 0 additions & 2 deletions tests/trust_metric_all/node/full_node/default_start.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -485,7 +484,6 @@ pub async fn start<Mapping: 'static + ServiceMapping>(
});

exec_demon.run().await;

let _ = consensus_handle.await;
let _ = running;

Expand Down

0 comments on commit 5ff6010

Please sign in to comment.