Skip to content

Commit

Permalink
[Smoke Tests] Add smoke tests for manual VFN forking.
Browse files Browse the repository at this point in the history
  • Loading branch information
JoshLind committed Nov 17, 2023
1 parent e08c3f1 commit 2a0c2b3
Show file tree
Hide file tree
Showing 6 changed files with 328 additions and 140 deletions.
18 changes: 14 additions & 4 deletions testsuite/forge/src/backend/local/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,16 +430,14 @@ impl LocalSwarm {
}

pub fn validators(&self) -> impl Iterator<Item = &LocalNode> {
// sort by id to keep the order consistent:
let mut validators: Vec<&LocalNode> = self.validators.values().collect();
validators.sort_by_key(|v| v.index());
validators.sort_by_key(|v| v.index()); // Sort by index for consistent ordering
validators.into_iter()
}

pub fn validators_mut(&mut self) -> impl Iterator<Item = &mut LocalNode> {
// sort by id to keep the order consistent:
let mut validators: Vec<&mut LocalNode> = self.validators.values_mut().collect();
validators.sort_by_key(|v| v.index());
validators.sort_by_key(|v| v.index()); // Sort by index for consistent ordering
validators.into_iter()
}

Expand All @@ -451,6 +449,18 @@ impl LocalSwarm {
self.fullnodes.get_mut(&peer_id)
}

pub fn fullnodes(&self) -> impl Iterator<Item = &LocalNode> {
let mut fullnodes: Vec<&LocalNode> = self.fullnodes.values().collect();
fullnodes.sort_by_key(|v| v.index()); // Sort by index for consistent ordering
fullnodes.into_iter()
}

pub fn fullnodes_mut(&mut self) -> impl Iterator<Item = &mut LocalNode> {
let mut fullnodes: Vec<&mut LocalNode> = self.fullnodes.values_mut().collect();
fullnodes.sort_by_key(|v| v.index()); // Sort by index for consistent ordering
fullnodes.into_iter()
}

pub fn dir(&self) -> &Path {
self.dir.as_ref()
}
Expand Down
17 changes: 13 additions & 4 deletions testsuite/forge/src/interface/node.rs
Original file line number Diff line number Diff line change
Expand Up @@ -77,18 +77,27 @@ pub trait Node: Send + Sync {
/// Trait used to represent a running Validator
#[async_trait::async_trait]
pub trait Validator: Node + Sync {
async fn check_connectivity(&self, expected_peers: usize) -> Result<bool> {
async fn check_connectivity(
&self,
network_id: NetworkId,
expected_peers: usize,
) -> Result<bool> {
if expected_peers == 0 {
return Ok(true);
}

self.get_connected_peers(NetworkId::Validator, None)
self.get_connected_peers(network_id, None)
.await
.map(|maybe_n| maybe_n.map(|n| n >= expected_peers as i64).unwrap_or(false))
}

async fn wait_for_connectivity(&self, expected_peers: usize, deadline: Instant) -> Result<()> {
while !self.check_connectivity(expected_peers).await? {
async fn wait_for_connectivity(
&self,
network_id: NetworkId,
expected_peers: usize,
deadline: Instant,
) -> Result<()> {
while !self.check_connectivity(network_id, expected_peers).await? {
if Instant::now() > deadline {
return Err(anyhow!("waiting for connectivity timed out"));
}
Expand Down
9 changes: 6 additions & 3 deletions testsuite/forge/src/interface/swarm.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,10 @@ use crate::{
AptosPublicInfo, ChainInfo, FullNode, NodeExt, Result, SwarmChaos, Validator, Version,
};
use anyhow::{anyhow, bail};
use aptos_config::config::{NodeConfig, OverrideNodeConfig};
use aptos_config::{
config::{NodeConfig, OverrideNodeConfig},
network_id::NetworkId,
};
use aptos_logger::info;
use aptos_rest_client::Client as RestClient;
use aptos_sdk::types::PeerId;
Expand Down Expand Up @@ -157,7 +160,7 @@ pub trait SwarmExt: Swarm {
while !try_join_all(
validators
.iter()
.map(|node| node.check_connectivity(validators.len() - 1))
.map(|node| node.check_connectivity(NetworkId::Validator, validators.len() - 1))
.chain(full_nodes.iter().map(|node| node.check_connectivity())),
)
.await
Expand Down Expand Up @@ -492,7 +495,7 @@ pub async fn get_highest_synced_epoch(clients: &[(String, RestClient)]) -> Resul
}

/// Returns the highest synced version and epoch of the given clients
async fn get_highest_synced_version_and_epoch(
pub async fn get_highest_synced_version_and_epoch(
clients: &[(String, RestClient)],
) -> Result<(u64, u64)> {
let mut latest_version_and_epoch = (0, 0);
Expand Down
Loading

0 comments on commit 2a0c2b3

Please sign in to comment.