Skip to content

Commit

Permalink
Fix receiver dropping bug in test_stabilization_final_dht
Browse files Browse the repository at this point in the history
  • Loading branch information
Ma233 committed Mar 25, 2024
1 parent a12bd72 commit d3958f7
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 2 deletions.
6 changes: 5 additions & 1 deletion crates/core/src/tests/default/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,11 @@ impl SwarmCallback for NodeCallback {
&self,
payload: &MessagePayload,
) -> Result<(), Box<dyn std::error::Error>> {
self.message_tx.send(payload.clone()).map_err(|e| e.into())
// Here we are using on_validate to record messages.
// When on_validate return error, the message will be ignored, which is not on purpose.
// To prevent returning errors when sending fails, we choose to panic instead.
self.message_tx.send(payload.clone()).unwrap();
Ok(())
}
}

Expand Down
6 changes: 5 additions & 1 deletion crates/core/src/tests/default/test_stabilization.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,10 +96,13 @@ async fn test_stabilization() -> Result<()> {
}

#[tokio::test]
#[ignore]
async fn test_stabilization_final_dht() -> Result<()> {
let mut swarms = vec![];

// Store the nodes to prevent the receiver from being dropped.
// That will cause the callback monitor panic when record message.
let mut nodes = vec![];

let keys = vec![
"af3543cde0c40fd217c536a358fb5f3c609eb1135f68daf7e2f2fbd51f164221", // 0xfe81c75f0ef75d7436b84089c5be31b692518d73
"d842f7143beac06ab8d81589c3c53cffd7eb8e07dadae8fdcb3ed1e1319ab477", // 0x8d4300b4df3c85ee107009e354c1b95717ab1c17
Expand All @@ -111,6 +114,7 @@ async fn test_stabilization_final_dht() -> Result<()> {
let node = prepare_node(key).await;
swarms.push(node.swarm.clone());
let stabilization = Arc::new(Stabilization::new(node.swarm.clone(), 3));
nodes.push(node);
tokio::spawn(stabilization.wait());
}

Expand Down

0 comments on commit d3958f7

Please sign in to comment.