mod utils;
use self::utils::*;
use anyhow::{anyhow, Result};
use bytes::Bytes;
use sn_messaging::{Aggregation, DstLocation, Itinerary, SrcLocation};
use sn_routing::{Event, NodeElderChange};
#[tokio::test]
async fn test_node_drop() -> Result<()> {
let mut nodes = create_connected_nodes(4).await?;
for (_, events) in &mut nodes[1..] {
assert_event!(
events,
Event::EldersChanged {
self_status_change: NodeElderChange::Promoted,
..
}
);
}
let node_count = nodes.len();
for (node, events) in &mut nodes {
if node.our_elders().await.len() == node_count {
continue;
}
assert_event!(events, Event::EldersChanged { elders, .. } if (elders.remaining.len() + elders.added.len()) == node_count);
}
let dropped_node = nodes.remove(1).0;
let dropped_name = dropped_node.name().await;
let dropped_addr = dropped_node.our_connection_info();
drop(dropped_node);
tracing::info!("Dropped {} at {}", dropped_name, dropped_addr);
{
let (node, _) = nodes.iter().last().ok_or_else(|| anyhow!("Missing Node"))?;
let itinerary = Itinerary {
src: SrcLocation::Node(node.name().await),
dst: DstLocation::Node(dropped_name),
aggregation: Aggregation::None,
};
node.send_message(itinerary, Bytes::from(b"hello".to_vec()), None)
.await?
}
for (_, events) in &mut nodes {
assert_event!(events, Event::MemberLeft { name, .. } if name == dropped_name)
}
Ok(())
}