Skip to content

Commit

Permalink
add failing regression test to prevent dead locking
Browse files Browse the repository at this point in the history
  • Loading branch information
jost-s committed Aug 2, 2024
1 parent 3496a66 commit da0e7da
Showing 1 changed file with 27 additions and 0 deletions.
27 changes: 27 additions & 0 deletions crates/tx5/src/test.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
use tokio::time::timeout;

use crate::*;

struct TestEp {
Expand Down Expand Up @@ -631,3 +633,28 @@ async fn ep_broadcast_happy() {
let (_, message) = ep3_recv.recv().await.unwrap();
assert_eq!(&b"world"[..], &message);
}

// Regression test to prevent dead locking a connection when a peer attempts to
// connect to itself.
#[tokio::test(flavor = "multi_thread")]
async fn connect_to_self_does_not_dead_lock() {
let config = Arc::new(Config {
signal_allow_plain_text: true,
..Default::default()
});
let test = Test::new().await;

let mut ep1 = test.ep(config.clone()).await;
let mut ep1_recv = ep1.take_recv().unwrap();
let message = b"hello";

let result = timeout(
std::time::Duration::from_secs(1),
ep1.send(ep1.peer_url(), message.to_vec()),
)
.await;
assert!(result.is_ok());

let (_, message) = ep1_recv.recv().await.unwrap();
assert_eq!(&message.to_vec(), &message);
}

0 comments on commit da0e7da

Please sign in to comment.