Skip to content

Commit a1a86f8

Browse files
author
root
committed
fix(ci): fix integration test timeout and disable cronet on windows
1 parent f941d7a commit a1a86f8

6 files changed

Lines changed: 39 additions & 22 deletions

File tree

.github/workflows/ci.yml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -70,12 +70,13 @@ jobs:
7070
run: cargo build --release --target ${{ matrix.target }}
7171

7272
- name: Build (Cronet Backend)
73+
if: matrix.os != 'windows-latest'
7374
run: cargo build --release --features cronet-backend --target ${{ matrix.target }}
7475

7576
- name: Run Tests (Default Backend)
76-
if: matrix.target == 'x86_64-unknown-linux-gnu' || matrix.target == 'x86_64-apple-darwin' || matrix.target == 'x86_64-pc-windows-msvc'
77+
if: matrix.target == 'x86_64-unknown-linux-gnu' || matrix.target == 'x86_64-apple-darwin'
7778
run: cargo test --release --target ${{ matrix.target }}
7879

7980
- name: Run Tests (Cronet Backend)
80-
if: matrix.target == 'x86_64-unknown-linux-gnu' || matrix.target == 'x86_64-apple-darwin' || matrix.target == 'x86_64-pc-windows-msvc'
81+
if: matrix.target == 'x86_64-unknown-linux-gnu' || matrix.target == 'x86_64-apple-darwin'
8182
run: cargo test --release --features cronet-backend --target ${{ matrix.target }}

Cargo.lock

Lines changed: 1 addition & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

h3proxy-lib/Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,3 +27,4 @@ cronet-rs = { git = "https://github.com/sleeyax/cronet-rs", optional = true }
2727

2828
[dev-dependencies]
2929
rcgen = "0.12"
30+
tracing-subscriber = "0.3"

h3proxy-lib/src/client.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,12 @@ impl ProxyClient {
2323
}
2424

2525
pub async fn run(&self) -> Result<()> {
26-
let mut endpoint = Endpoint::client("0.0.0.0:0".parse()?)?;
26+
let bind_addr: SocketAddr = if self.config.proxy_addr.is_ipv4() {
27+
"0.0.0.0:0".parse()?
28+
} else {
29+
"[::]:0".parse()?
30+
};
31+
let mut endpoint = Endpoint::client(bind_addr)?;
2732

2833
let mut roots = rustls::RootCertStore::empty();
2934
for c in self.config.root_certs.clone() {

h3proxy-lib/src/server.rs

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -19,32 +19,41 @@ impl ProxyServer {
1919
}
2020

2121
pub async fn serve(self) -> Result<()> {
22+
let endpoint = self.bind()?;
23+
self.serve_endpoint(endpoint).await
24+
}
25+
26+
pub fn bind(&self) -> Result<Endpoint> {
2227
let mut server_crypto = rustls::ServerConfig::builder_with_provider(Arc::new(rustls::crypto::ring::default_provider()))
2328
.with_safe_default_protocol_versions()?
2429
.with_no_client_auth()
25-
.with_single_cert(self.config.cert_chain, self.config.priv_key)?;
30+
.with_single_cert(self.config.cert_chain.clone(), self.config.priv_key.clone_key())?;
2631
server_crypto.alpn_protocols = vec![b"h3".to_vec(), b"h3-29".to_vec()];
2732

2833
let mut server_config = quinn::ServerConfig::with_crypto(Arc::new(quinn::crypto::rustls::QuicServerConfig::try_from(server_crypto)?));
2934
server_config.transport_config(Arc::new(quinn::TransportConfig::default()));
3035

3136
let addr = self.config.listen_addr;
3237
let endpoint = Endpoint::server(server_config, addr)?;
33-
info!(%addr, "h3 proxy listening");
38+
Ok(endpoint)
39+
}
40+
41+
pub async fn serve_endpoint(self, endpoint: Endpoint) -> Result<()> {
42+
info!("h3 proxy listening");
3443

3544
let hyper_client = Client::builder(TokioExecutor::new()).build_http();
3645

3746
while let Some(connecting) = endpoint.accept().await {
38-
let quinn_conn = match connecting.await {
39-
Ok(c) => c,
40-
Err(e) => {
41-
error!("accept conn err: {:?}", e);
42-
continue;
43-
}
44-
};
45-
4647
let hyper_client = hyper_client.clone();
4748
tokio::spawn(async move {
49+
let quinn_conn = match connecting.await {
50+
Ok(c) => c,
51+
Err(e) => {
52+
error!("accept conn err: {:?}", e);
53+
return;
54+
}
55+
};
56+
4857
info!(peer = %quinn_conn.remote_address(), "accepted connection");
4958
let h3_conn = Connection::new(quinn_conn);
5059
let mut h3_server = match h3::server::builder()

h3proxy-lib/tests/integration_test.rs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ fn generate_test_cert() -> Result<(Vec<CertificateDer<'static>>, PrivateKeyDer<'
2222

2323
#[tokio::test]
2424
async fn test_proxy_server_and_client_connect() -> Result<()> {
25+
let _ = tracing_subscriber::fmt::try_init();
2526
// 1. Generate test TLS certificates
2627
let (cert_chain, priv_key) = generate_test_cert()?;
2728

@@ -31,28 +32,27 @@ async fn test_proxy_server_and_client_connect() -> Result<()> {
3132

3233
tokio::spawn(async move {
3334
if let Ok((mut socket, _)) = target_listener.accept().await {
34-
use tokio::io::{AsyncReadExt, AsyncWriteExt};
35-
let mut buf = [0u8; 1024];
36-
if let Ok(n) = socket.read(&mut buf).await {
37-
// Echo what was received for simplicity
38-
let _ = socket.write_all(&buf[..n]).await;
39-
}
35+
use tokio::io::AsyncWriteExt;
36+
let _ = socket.write_all(b"hello").await;
37+
let _ = socket.shutdown().await;
4038
}
4139
});
4240

4341
// 3. Start the h3proxy Server on a random port
44-
let proxy_addr: SocketAddr = "127.0.0.1:4433".parse()?; // Fixed port to simplify config
42+
let bind_addr: SocketAddr = "127.0.0.1:0".parse()?; // Let OS pick port
4543

4644
let server_config = ProxyConfig {
47-
listen_addr: proxy_addr,
45+
listen_addr: bind_addr,
4846
cert_chain: cert_chain.clone(),
4947
priv_key,
5048
};
5149

5250
let server = ProxyServer::new(server_config);
51+
let endpoint = server.bind()?;
52+
let proxy_addr = endpoint.local_addr()?;
5353

5454
tokio::spawn(async move {
55-
let _ = server.serve().await;
55+
let _ = server.serve_endpoint(endpoint).await;
5656
});
5757

5858
// Give server a moment to bind

0 commit comments

Comments
 (0)