Skip to content

Commit 4ca9f2b

Browse files
committed
Add test for connection close.
1 parent 8ba7d91 commit 4ca9f2b

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

src/util/connection_pool.rs

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -804,4 +804,30 @@ mod tests {
804804
shutdown_routers(routers).await;
805805
Ok(())
806806
}
807+
808+
/// Check that when a connection is closed, the pool will give you a new
809+
/// connection next time you want one.
810+
///
811+
/// This test fails if the connection watch is disabled.
812+
#[tokio::test]
813+
#[traced_test]
814+
async fn watch_close() -> TestResult<()> {
815+
let n = 1;
816+
let (ids, routers, discovery) = echo_servers(n).await?;
817+
let endpoint = iroh::Endpoint::builder()
818+
.discovery(discovery)
819+
.bind()
820+
.await?;
821+
822+
let pool = ConnectionPool::new(endpoint, ECHO_ALPN, test_options());
823+
let conn = pool.get_or_connect(ids[0]).await?;
824+
let cid1 = conn.stable_id();
825+
conn.close(0u32.into(), b"test");
826+
tokio::time::sleep(Duration::from_millis(500)).await;
827+
let conn = pool.get_or_connect(ids[0]).await?;
828+
let cid2 = conn.stable_id();
829+
assert_ne!(cid1, cid2);
830+
shutdown_routers(routers).await;
831+
Ok(())
832+
}
807833
}

0 commit comments

Comments
 (0)