Skip to content

Commit

Permalink
[diem-swarm] Fix expected nodes
Browse files Browse the repository at this point in the history
Make sure number of expected nodes can't be negative.
  • Loading branch information
gregnazario authored and bors-libra committed Apr 2, 2021
1 parent bc9cf2d commit 5d0a2d3
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions testsuite/diem-swarm/src/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ use thiserror::Error;

pub struct DiemNode {
node: Child,
node_id: String,
pub(crate) node_id: String,
validator_peer_id: Option<AccountAddress>,
role: RoleType,
debug_client: NodeDebugClient,
Expand Down Expand Up @@ -129,13 +129,13 @@ impl DiemNode {
}
}

pub fn check_connectivity(&mut self, expected_peers: i64) -> bool {
pub fn check_connectivity(&mut self, expected_peers: usize) -> bool {
let connected_peers = format!(
"diem_network_peers{{role_type={},state=connected}}",
self.role.to_string()
);
if let Some(num_connected_peers) = self.get_metric(&connected_peers) {
if num_connected_peers < expected_peers {
if (num_connected_peers as usize) < expected_peers {
println!(
"Node '{}' Expected peers: {}, found peers: {}",
self.node_id, expected_peers, num_connected_peers
Expand Down Expand Up @@ -337,7 +337,7 @@ impl DiemSwarm {
self.nodes.insert(node_id, node);
}
let expected_peers = match self.role {
RoleType::Validator => self.nodes.len() as i64 - 1,
RoleType::Validator => self.nodes.len() - 1,
RoleType::FullNode => 1,
};
self.wait_for_startup()?;
Expand All @@ -346,7 +346,7 @@ impl DiemSwarm {
Ok(())
}

fn wait_for_connectivity(&mut self, expected_peers: i64) -> Result<(), SwarmLaunchFailure> {
fn wait_for_connectivity(&mut self, expected_peers: usize) -> Result<(), SwarmLaunchFailure> {
// Early return if we're only launching a single node
if self.nodes.len() == 1 {
return Ok(());
Expand Down Expand Up @@ -534,7 +534,7 @@ impl DiemSwarm {
for _ in 0..60 {
if let HealthStatus::Healthy = node.health_check() {
self.nodes.insert(node_id, node);
return self.wait_for_connectivity(self.nodes.len() as i64 - 1);
return self.wait_for_connectivity(self.nodes.len() - 1);
}
::std::thread::sleep(::std::time::Duration::from_millis(1000));
}
Expand Down

0 comments on commit 5d0a2d3

Please sign in to comment.