Skip to content

Commit

Permalink
feat(test): assert PeerIds are not the same after restart
Browse files Browse the repository at this point in the history
  • Loading branch information
RolandSherwin committed Feb 12, 2024
1 parent 950bb25 commit 490db5d
Showing 1 changed file with 14 additions and 1 deletion.
15 changes: 14 additions & 1 deletion sn_node/tests/common/mod.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright 2024 MaidSafe.net limited.
// Copyright 2023 MaidSafe.net limited.
//
// This SAFE Network Software is licensed to you under The General Public License (GPL), version 3.
// Unless required by applicable law or agreed to in writing, the SAFE Network Software distributed
Expand Down Expand Up @@ -106,13 +106,15 @@ pub async fn get_all_peer_ids(node_rpc_addresses: &Vec<SocketAddr>) -> Result<Ve
Ok(all_peers)
}

/// Also asserts that the node restarted with a new PeerId. This adds an inherent 5s delay to this function.
pub async fn node_restart(addr: &SocketAddr) -> Result<()> {
let mut rpc_client = get_safenode_rpc_client(*addr).await?;

let response = rpc_client
.node_info(Request::new(NodeInfoRequest {}))
.await?;
let root_dir = Path::new(&response.get_ref().data_dir);
let previous_peer_id = PeerId::from_bytes(&response.get_ref().peer_id)?;
debug!("Obtained root dir from node {root_dir:?}.");

let record_store = root_dir.join("record_store");
Expand Down Expand Up @@ -141,5 +143,16 @@ pub async fn node_restart(addr: &SocketAddr) -> Result<()> {
println!("Node restart requested to RPC service at {addr}");
info!("Node restart requested to RPC service at {addr}");

tokio::time::sleep(Duration::from_secs(5)).await;
println!("Verifying if the node restarted with a different PeerId");
info!("Verifying if the node restarted with a different PeerId");
let response = rpc_client
.node_info(Request::new(NodeInfoRequest {}))
.await?;
let current_peer_id = PeerId::from_bytes(&response.get_ref().peer_id)?;
if current_peer_id == previous_peer_id {
bail!("The PeerIds are not the same after restart. previous: {previous_peer_id:?}, current: {current_peer_id:?}");
}

Ok(())
}

0 comments on commit 490db5d

Please sign in to comment.