Skip to content

Commit 4595a08

Browse files
authored
tests: fix cargo test ... for a variety of features (#266)
This patch fixes a number of test combinations that were failing before: * `cargo test` * `cargo test --features client-legacy` * `cargo test --features client-legacy,http1` * `cargo test --features client-legacy,http2` * `cargo test --features client-legacy,http1,http2` I would have expected this to have been caught by `cargo hack` but I'm guessing it wasn't testing at this depth.
1 parent 7252393 commit 4595a08

File tree

4 files changed

+28
-4
lines changed

4 files changed

+28
-4
lines changed

src/client/legacy/client.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ impl Client<(), ()> {
118118
/// # Example
119119
///
120120
/// ```
121-
/// # #[cfg(feature = "tokio")]
121+
/// # #[cfg(all(feature = "tokio", feature = "http2"))]
122122
/// # fn run () {
123123
/// use std::time::Duration;
124124
/// use hyper_util::client::legacy::Client;
@@ -994,7 +994,7 @@ fn is_schema_secure(uri: &Uri) -> bool {
994994
/// # Example
995995
///
996996
/// ```
997-
/// # #[cfg(feature = "tokio")]
997+
/// # #[cfg(all(feature = "tokio", feature = "http2"))]
998998
/// # fn run () {
999999
/// use std::time::Duration;
10001000
/// use hyper_util::client::legacy::Client;
@@ -1057,7 +1057,7 @@ impl Builder {
10571057
/// # Example
10581058
///
10591059
/// ```
1060-
/// # #[cfg(feature = "tokio")]
1060+
/// # #[cfg(all(feature = "tokio", feature = "http2"))]
10611061
/// # fn run () {
10621062
/// use std::time::Duration;
10631063
/// use hyper_util::client::legacy::Client;

src/client/legacy/connect/capture.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ pub struct CaptureConnection {
4747
/// connection is available.
4848
///
4949
/// ```rust
50-
/// # #[cfg(feature = "tokio")]
50+
/// # #[cfg(all(feature = "tokio", any(feature = "http1", feature = "http2")))]
5151
/// # async fn example() {
5252
/// use hyper_util::client::legacy::connect::capture_connection;
5353
/// use hyper_util::client::legacy::Client;

tests/legacy_client.rs

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(all(feature = "client-legacy", any(feature = "http1", feature = "http2")))]
2+
13
mod test_utils;
24

35
use std::io::{Read, Write};
@@ -38,6 +40,7 @@ fn s(buf: &[u8]) -> &str {
3840
}
3941

4042
#[cfg(not(miri))]
43+
#[cfg(feature = "http1")]
4144
#[test]
4245
fn drop_body_before_eof_closes_connection() {
4346
// https://github.com/hyperium/hyper/issues/1353
@@ -86,6 +89,7 @@ fn drop_body_before_eof_closes_connection() {
8689
}
8790

8891
#[cfg(not(miri))]
92+
#[cfg(feature = "http1")]
8993
#[tokio::test]
9094
async fn drop_client_closes_idle_connections() {
9195
let _ = pretty_env_logger::try_init();
@@ -150,6 +154,7 @@ async fn drop_client_closes_idle_connections() {
150154
}
151155

152156
#[cfg(not(miri))]
157+
#[cfg(feature = "http1")]
153158
#[tokio::test]
154159
async fn drop_response_future_closes_in_progress_connection() {
155160
let _ = pretty_env_logger::try_init();
@@ -199,6 +204,7 @@ async fn drop_response_future_closes_in_progress_connection() {
199204
}
200205

201206
#[cfg(not(miri))]
207+
#[cfg(feature = "http1")]
202208
#[tokio::test]
203209
async fn drop_response_body_closes_in_progress_connection() {
204210
let _ = pretty_env_logger::try_init();
@@ -255,6 +261,7 @@ async fn drop_response_body_closes_in_progress_connection() {
255261
}
256262

257263
#[cfg(not(miri))]
264+
#[cfg(feature = "http1")]
258265
#[tokio::test]
259266
async fn no_keep_alive_closes_connection() {
260267
// https://github.com/hyperium/hyper/issues/1383
@@ -308,6 +315,7 @@ async fn no_keep_alive_closes_connection() {
308315
}
309316

310317
#[cfg(not(miri))]
318+
#[cfg(feature = "http1")]
311319
#[tokio::test]
312320
async fn socket_disconnect_closes_idle_conn() {
313321
// notably when keep-alive is enabled
@@ -378,6 +386,7 @@ fn connect_call_is_lazy() {
378386
}
379387

380388
#[cfg(not(miri))]
389+
#[cfg(feature = "http1")]
381390
#[test]
382391
fn client_keep_alive_0() {
383392
let _ = pretty_env_logger::try_init();
@@ -445,6 +454,7 @@ fn client_keep_alive_0() {
445454
}
446455

447456
#[cfg(not(miri))]
457+
#[cfg(feature = "http1")]
448458
#[test]
449459
fn client_keep_alive_extra_body() {
450460
let _ = pretty_env_logger::try_init();
@@ -508,6 +518,7 @@ fn client_keep_alive_extra_body() {
508518
}
509519

510520
#[cfg(not(miri))]
521+
#[cfg(feature = "http1")]
511522
#[tokio::test]
512523
async fn client_keep_alive_when_response_before_request_body_ends() {
513524
let _ = pretty_env_logger::try_init();
@@ -577,6 +588,7 @@ async fn client_keep_alive_when_response_before_request_body_ends() {
577588
}
578589

579590
#[cfg(not(miri))]
591+
#[cfg(feature = "http1")]
580592
#[tokio::test]
581593
async fn client_keep_alive_eager_when_chunked() {
582594
// If a response body has been read to completion, with completion
@@ -663,6 +675,7 @@ async fn client_keep_alive_eager_when_chunked() {
663675
}
664676

665677
#[cfg(not(miri))]
678+
#[cfg(feature = "http1")]
666679
#[test]
667680
fn connect_proxy_sends_absolute_uri() {
668681
let _ = pretty_env_logger::try_init();
@@ -700,6 +713,7 @@ fn connect_proxy_sends_absolute_uri() {
700713
}
701714

702715
#[cfg(not(miri))]
716+
#[cfg(feature = "http1")]
703717
#[test]
704718
fn connect_proxy_http_connect_sends_authority_form() {
705719
let _ = pretty_env_logger::try_init();
@@ -738,6 +752,7 @@ fn connect_proxy_http_connect_sends_authority_form() {
738752
}
739753

740754
#[cfg(not(miri))]
755+
#[cfg(feature = "http1")]
741756
#[test]
742757
fn client_upgrade() {
743758
use tokio::io::{AsyncReadExt, AsyncWriteExt};
@@ -800,6 +815,7 @@ fn client_upgrade() {
800815
}
801816

802817
#[cfg(not(miri))]
818+
#[cfg(feature = "server")]
803819
#[test]
804820
fn client_http2_upgrade() {
805821
use http::{Method, Response, Version};
@@ -882,6 +898,7 @@ fn client_http2_upgrade() {
882898
}
883899

884900
#[cfg(not(miri))]
901+
#[cfg(feature = "http2")]
885902
#[test]
886903
fn alpn_h2() {
887904
use http::Response;
@@ -950,6 +967,7 @@ fn alpn_h2() {
950967
}
951968

952969
#[cfg(not(miri))]
970+
#[cfg(feature = "http1")]
953971
#[test]
954972
fn capture_connection_on_client() {
955973
let _ = pretty_env_logger::try_init();
@@ -981,6 +999,7 @@ fn capture_connection_on_client() {
981999
}
9821000

9831001
#[cfg(not(miri))]
1002+
#[cfg(feature = "http1")]
9841003
#[test]
9851004
fn connection_poisoning() {
9861005
use std::sync::atomic::AtomicUsize;
@@ -1327,6 +1346,7 @@ impl tower_service::Service<hyper::Uri> for MockConnector {
13271346
// Test for connection error propagation with PR #184.
13281347
// Simulates a connection failure by setting failed=true and returning a custom io::Error.
13291348
// Verifies the error propagates through hyper’s client as a hyper::Error(Io, ...).
1349+
#[cfg(feature = "http1")]
13301350
#[tokio::test]
13311351
async fn test_connection_error_propagation_pr184() {
13321352
// Define the error message for the simulated connection failure.
@@ -1384,6 +1404,7 @@ async fn test_connection_error_propagation_pr184() {
13841404
// Simulates a connection that returns EOF immediately, causing hyper’s HTTP/1.1 parser
13851405
// to fail with IncompleteMessage due to no response data.
13861406
// Uses MockConnector with conn_error=None to keep failed=false, ensuring EOF behavior.
1407+
#[cfg(feature = "http1")]
13871408
#[tokio::test]
13881409
async fn test_incomplete_message_error_pr184() {
13891410
// Create an empty IoBuilder to simulate a connection with no data.
@@ -1443,6 +1464,7 @@ async fn test_incomplete_message_error_pr184() {
14431464
// Test for a successful HTTP/1.1 connection using a mock connector.
14441465
// Simulates a server that accepts a request and responds with a 200 OK.
14451466
// Verifies the client correctly sends the request and receives the response.
1467+
#[cfg(feature = "http1")]
14461468
#[tokio::test]
14471469
async fn test_successful_connection() {
14481470
// Define the expected server response: a valid HTTP/1.1 200 OK with no body.

tests/proxy.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#![cfg(all(feature = "client-legacy", feature = "client-proxy"))]
2+
13
use tokio::io::{AsyncReadExt, AsyncWriteExt};
24
use tokio::net::{TcpListener, TcpStream};
35
use tower_service::Service;

0 commit comments

Comments
 (0)