Skip to content

Commit

Permalink
test: add H3ClientStream Clonable test
Browse files Browse the repository at this point in the history
  • Loading branch information
0xffffharry committed Apr 16, 2024
1 parent e088e09 commit 54f4963
Showing 1 changed file with 50 additions and 0 deletions.
50 changes: 50 additions & 0 deletions crates/proto/src/h3/h3_client_stream.rs
Expand Up @@ -472,6 +472,7 @@ mod tests {

use rustls::KeyLogFile;
use tokio::runtime::Runtime;
use tokio::task::JoinSet;

use crate::op::{Message, Query, ResponseCode};
use crate::rr::rdata::{A, AAAA};
Expand Down Expand Up @@ -671,4 +672,53 @@ mod tests {
&AAAA::new(0x2606, 0x2800, 0x0220, 0x0001, 0x0248, 0x1893, 0x25c8, 0x1946)
);
}

#[test]
fn test_h3_client_stream_clonable() {

// use google
let google = SocketAddr::from(([8, 8, 8, 8], 443));

let mut client_config = super::super::client_config_tls13().unwrap();
client_config.key_log = Arc::new(KeyLogFile::new());

let mut h3_builder = H3ClientStream::builder();
h3_builder.crypto_config(client_config);
let connect = h3_builder.build(google, "dns.google".to_string());

// tokio runtime stuff...
let runtime = Runtime::new().expect("could not start runtime");
let h3 = runtime.block_on(connect).expect("h3 connect failed");

// prepare request
let mut request = Message::new();
let query = Query::query(
Name::from_str("www.example.com.").unwrap(),
RecordType::AAAA,
);
request.add_query(query);
let request = DnsRequest::new(request, DnsRequestOptions::default());

runtime.block_on(async move {
let mut join_set = JoinSet::new();

for i in 0..50 {
let mut h3 = h3.clone();
let request = request.clone();

join_set.spawn(async move {
let start = std::time::Instant::now();
h3.send_message(request).first_answer().await.expect("send_message failed");
println!("request[{i}] completed: {:?}", start.elapsed());
});
}

let total = join_set.len();
let mut idx = 0usize;
while let Some(_) = join_set.join_next().await {
println!("join_set completed {idx}/{total}");
idx += 1;
}
});
}
}

0 comments on commit 54f4963

Please sign in to comment.