Skip to content

Commit

Permalink
smoke-test: convert network tests to use LocalSwarm
Browse files Browse the repository at this point in the history
  • Loading branch information
bmwill authored and bors-libra committed Sep 3, 2021
1 parent 3cd6871 commit fc9eb8d
Show file tree
Hide file tree
Showing 4 changed files with 194 additions and 68 deletions.
8 changes: 8 additions & 0 deletions testsuite/forge/src/backend/local/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -371,6 +371,14 @@ impl LocalSwarm {
self.validators.values_mut()
}

pub fn fullnode(&self, peer_id: PeerId) -> Option<&LocalNode> {
self.fullnodes.get(&peer_id)
}

pub fn fullnode_mut(&mut self, peer_id: PeerId) -> Option<&mut LocalNode> {
self.fullnodes.get_mut(&peer_id)
}

pub fn dir(&self) -> &Path {
self.dir.as_ref()
}
Expand Down
25 changes: 25 additions & 0 deletions testsuite/forge/src/interface/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0

use crate::{Result, Version};
use anyhow::anyhow;
use debug_interface::NodeDebugClient;
use diem_config::{config::NodeConfig, network_id::NetworkId};
use diem_sdk::{
Expand Down Expand Up @@ -75,6 +76,18 @@ pub trait Validator: Node {
self.get_connected_peers(NetworkId::Validator, None)
.map(|maybe_n| maybe_n.map(|n| n >= expected_peers as i64).unwrap_or(false))
}

fn wait_for_connectivity(&self, expected_peers: usize, deadline: Instant) -> Result<()> {
while !self.check_connectivity(expected_peers)? {
if Instant::now() > deadline {
return Err(anyhow!("waiting for connectivity timed out"));
}

thread::sleep(Duration::from_millis(500));
}

Ok(())
}
}

/// Trait used to represent a running FullNode
Expand All @@ -87,6 +100,18 @@ pub trait FullNode: Node {
self.get_connected_peers(NetworkId::Public, DIRECTION)
.map(|maybe_n| maybe_n.map(|n| n >= EXPECTED_PEERS as i64).unwrap_or(false))
}

fn wait_for_connectivity(&self, deadline: Instant) -> Result<()> {
while !self.check_connectivity()? {
if Instant::now() > deadline {
return Err(anyhow!("waiting for connectivity timed out"));
}

thread::sleep(Duration::from_millis(500));
}

Ok(())
}
}

impl<T: ?Sized> NodeExt for T where T: Node {}
Expand Down
7 changes: 2 additions & 5 deletions testsuite/smoke-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@ mod genesis;
#[cfg(test)]
mod key_manager;
#[cfg(test)]
mod network;
#[cfg(test)]
mod operational_tooling;
#[cfg(test)]
mod release_flow;
Expand All @@ -29,11 +31,6 @@ mod state_sync;
#[cfg(test)]
mod storage;

// Left to convert

#[cfg(test)]
mod network;

#[cfg(test)]
mod smoke_test_environment;

Expand Down
Loading

0 comments on commit fc9eb8d

Please sign in to comment.