Skip to content

Commit

Permalink
Merge pull request #6 from zeroqn/fix-trust-metrics-integration-tests…
Browse files Browse the repository at this point in the history
…-panic-rpc-timeout

fix(trust_metric_test): check running status before rpc and broadcast
  • Loading branch information
yejiayu authored Jul 3, 2020
2 parents ec82837 + 5ff6010 commit 9934580
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
5 changes: 2 additions & 3 deletions tests/trust_metric_all/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,8 @@ fn trust_test(test: impl FnOnce(ClientNode) -> BoxFuture<'static, ()> + Send + '

local.block_on(&mut rt, async move {
let running = common::RunningStatus::new();
let _ = panic::catch_unwind(panic::AssertUnwindSafe(|| {
let _ = tokio::task::spawn_local(node::full_node::run(full_port, running.clone()));
}));
tokio::task::spawn_local(node::full_node::run(full_port, running.clone()));

// Sleep a while for full node network to running, otherwise will
// trigger network retry back off.
tokio::time::delay_for(std::time::Duration::from_secs(FULL_NODE_SETUP_WAIT_TIME)).await;
Expand Down
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
5 changes: 3 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 @@ -474,7 +474,7 @@ pub async fn start<Mapping: 'static + ServiceMapping>(
brake_ratio: metadata.brake_ratio,
};

tokio::spawn(async move {
let consensus_handle = tokio::spawn(async move {
if let Err(e) = overlord_consensus
.run(consensus_interval, authority_list, Some(timer_config))
.await
Expand All @@ -483,8 +483,9 @@ pub async fn start<Mapping: 'static + ServiceMapping>(
}
});

let _ = running;
exec_demon.run().await;
let _ = consensus_handle.await;
let _ = running;

Ok(())
}

0 comments on commit 9934580

Please sign in to comment.