Skip to content

Commit 07ce61c

Browse files
committed
Test cleanup of connections/endpoints when all references are dropped
1 parent 06f7f7d commit 07ce61c

2 files changed

Lines changed: 38 additions & 1 deletion

File tree

quinn/Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,7 @@ directories-next = { workspace = true }
7979
rand = { workspace = true }
8080
rcgen = { workspace = true }
8181
clap = { workspace = true }
82-
tokio = { workspace = true, features = ["rt", "rt-multi-thread", "time", "macros"] }
82+
tokio = { workspace = true, features = ["rt", "rt-multi-thread", "time", "macros", "test-util"] }
8383
tracing-subscriber = { workspace = true }
8484
tracing-futures = { workspace = true }
8585
url = { workspace = true }

quinn/src/tests.rs

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1057,6 +1057,43 @@ async fn recv_stream_cancel_stop_drop() {
10571057
);
10581058
}
10591059

1060+
#[tokio::test(start_paused = true)]
1061+
async fn dropped_endpoint_cleans_up() {
1062+
let _guard = subscribe();
1063+
1064+
let mut endpoint_factory = EndpointFactory::new();
1065+
let cid_generator = Arc::new(|| -> Box<dyn proto::ConnectionIdGenerator> {
1066+
Box::<proto::HashedConnectionIdGenerator>::default()
1067+
});
1068+
endpoint_factory
1069+
.endpoint_config
1070+
.cid_generator(cid_generator.clone());
1071+
let endpoint = endpoint_factory.endpoint();
1072+
drop(endpoint_factory);
1073+
assert_eq!(Arc::strong_count(&cid_generator), 2);
1074+
drop(endpoint);
1075+
// Let the driver task run; paused runtimes are guaranteed to drain pending work on sleep.
1076+
tokio::time::sleep(Duration::from_millis(1)).await;
1077+
assert_eq!(Arc::strong_count(&cid_generator), 1);
1078+
}
1079+
1080+
#[tokio::test]
1081+
async fn dropped_connection_cleans_up() {
1082+
let _guard = subscribe();
1083+
let endpoint = endpoint();
1084+
join!(
1085+
async {
1086+
endpoint
1087+
.connect(endpoint.local_addr().unwrap(), "localhost")
1088+
.unwrap()
1089+
.await
1090+
.unwrap()
1091+
},
1092+
async { endpoint.accept().await.unwrap().await.unwrap() }
1093+
);
1094+
endpoint.wait_idle().await;
1095+
}
1096+
10601097
#[derive(Default)]
10611098
struct WakeCounter {
10621099
wakes: AtomicUsize,

0 commit comments

Comments
 (0)