Skip to content

chore(app/inbound): address hyper deprecations in http/1 tests #3454

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
113 changes: 84 additions & 29 deletions linkerd/app/inbound/src/http/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,7 @@ where
#[tokio::test(flavor = "current_thread")]
async fn unmeshed_http1_hello_world() {
let server = hyper::server::conn::http1::Builder::new();
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
let mut client = hyper::client::conn::http1::Builder::new();
let _trace = trace_init();

// Build a mock "connector" that returns the upstream "server" IO.
Expand All @@ -64,15 +63,15 @@ async fn unmeshed_http1_hello_world() {
let cfg = default_config();
let (rt, _shutdown) = runtime();
let server = build_server(cfg, rt, profiles, connect).new_service(Target::UNMESHED_HTTP1);
let (client, bg) = http_util::connect_and_accept(&mut client, server).await;
let (mut client, bg) = http_util::connect_and_accept_http1(&mut client, server).await;

let req = Request::builder()
.method(http::Method::GET)
.uri("http://foo.svc.cluster.local:5550")
.body(Body::default())
.unwrap();
let rsp = client
.oneshot(req)
.send_request(req)
.await
.expect("HTTP client request failed");
tracing::info!(?rsp);
Expand All @@ -81,6 +80,7 @@ async fn unmeshed_http1_hello_world() {
assert_eq!(body, "Hello world!");

// Wait for all of the background tasks to complete, panicking if any returned an error.
drop(client);
bg.join_all()
.await
.into_iter()
Expand All @@ -92,9 +92,7 @@ async fn unmeshed_http1_hello_world() {
async fn downgrade_origin_form() {
// Reproduces https://github.com/linkerd/linkerd2/issues/5298
let server = hyper::server::conn::http1::Builder::new();
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
client.http2_only(true);
let client = hyper::client::conn::http2::Builder::new(TracingExecutor);
let _trace = trace_init();

// Build a mock "connector" that returns the upstream "server" IO.
Expand All @@ -109,7 +107,35 @@ async fn downgrade_origin_form() {
let cfg = default_config();
let (rt, _shutdown) = runtime();
let server = build_server(cfg, rt, profiles, connect).new_service(Target::UNMESHED_H2);
let (client, bg) = http_util::connect_and_accept(&mut client, server).await;
let (mut client, bg) = {
tracing::info!(settings = ?client, "connecting client with");
let (client_io, server_io) = io::duplex(4096);

let (client, conn) = client
.handshake(client_io)
.await
.expect("Client must connect");

let mut bg = tokio::task::JoinSet::new();
bg.spawn(
async move {
server.oneshot(server_io).await?;
tracing::info!("proxy serve task complete");
Ok(())
}
.instrument(tracing::info_span!("proxy")),
);
bg.spawn(
async move {
conn.await?;
tracing::info!("client background complete");
Ok(())
}
.instrument(tracing::info_span!("client_bg")),
);

(client, bg)
};

let req = Request::builder()
.method(http::Method::GET)
Expand All @@ -119,7 +145,7 @@ async fn downgrade_origin_form() {
.body(Body::default())
.unwrap();
let rsp = client
.oneshot(req)
.send_request(req)
.await
.expect("HTTP client request failed");
tracing::info!(?rsp);
Expand All @@ -128,6 +154,7 @@ async fn downgrade_origin_form() {
assert_eq!(body, "Hello world!");

// Wait for all of the background tasks to complete, panicking if any returned an error.
drop(client);
bg.join_all()
.await
.into_iter()
Expand All @@ -137,10 +164,8 @@ async fn downgrade_origin_form() {

#[tokio::test(flavor = "current_thread")]
async fn downgrade_absolute_form() {
let client = hyper::client::conn::http2::Builder::new(TracingExecutor);
let server = hyper::server::conn::http1::Builder::new();
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
client.http2_only(true);
let _trace = trace_init();

// Build a mock "connector" that returns the upstream "server" IO.
Expand All @@ -155,7 +180,36 @@ async fn downgrade_absolute_form() {
let cfg = default_config();
let (rt, _shutdown) = runtime();
let server = build_server(cfg, rt, profiles, connect).new_service(Target::UNMESHED_H2);
let (client, bg) = http_util::connect_and_accept(&mut client, server).await;

let (mut client, bg) = {
tracing::info!(settings = ?client, "connecting client with");
let (client_io, server_io) = io::duplex(4096);

let (client, conn) = client
.handshake(client_io)
.await
.expect("Client must connect");

let mut bg = tokio::task::JoinSet::new();
bg.spawn(
async move {
server.oneshot(server_io).await?;
tracing::info!("proxy serve task complete");
Ok(())
}
.instrument(tracing::info_span!("proxy")),
);
bg.spawn(
async move {
conn.await?;
tracing::info!("client background complete");
Ok(())
}
.instrument(tracing::info_span!("client_bg")),
);

(client, bg)
};

let req = Request::builder()
.method(http::Method::GET)
Expand All @@ -165,7 +219,7 @@ async fn downgrade_absolute_form() {
.body(Body::default())
.unwrap();
let rsp = client
.oneshot(req)
.send_request(req)
.await
.expect("HTTP client request failed");
tracing::info!(?rsp);
Expand All @@ -174,6 +228,7 @@ async fn downgrade_absolute_form() {
assert_eq!(body, "Hello world!");

// Wait for all of the background tasks to complete, panicking if any returned an error.
drop(client);
bg.join_all()
.await
.into_iter()
Expand All @@ -190,16 +245,15 @@ async fn http1_bad_gateway_meshed_response_error_header() {

// Build a client using the connect that always errors so that responses
// are BAD_GATEWAY.
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
let mut client = hyper::client::conn::http1::Builder::new();
let profiles = profile::resolver();
let profile_tx =
profiles.profile_tx(NameAddr::from_str_and_port("foo.svc.cluster.local", 5550).unwrap());
profile_tx.send(profile::Profile::default()).unwrap();
let cfg = default_config();
let (rt, _shutdown) = runtime();
let server = build_server(cfg, rt, profiles, connect).new_service(Target::meshed_http1());
let (mut client, bg) = http_util::connect_and_accept(&mut client, server).await;
let (mut client, bg) = http_util::connect_and_accept_http1(&mut client, server).await;

// Send a request and assert that it is a BAD_GATEWAY with the expected
// header message.
Expand All @@ -221,6 +275,7 @@ async fn http1_bad_gateway_meshed_response_error_header() {
check_error_header(rsp.headers(), "server is not listening");

// Wait for all of the background tasks to complete, panicking if any returned an error.
drop(client);
bg.join_all()
.await
.into_iter()
Expand All @@ -237,16 +292,15 @@ async fn http1_bad_gateway_unmeshed_response() {

// Build a client using the connect that always errors so that responses
// are BAD_GATEWAY.
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
let mut client = hyper::client::conn::http1::Builder::new();
let profiles = profile::resolver();
let profile_tx =
profiles.profile_tx(NameAddr::from_str_and_port("foo.svc.cluster.local", 5550).unwrap());
profile_tx.send(profile::Profile::default()).unwrap();
let cfg = default_config();
let (rt, _shutdown) = runtime();
let server = build_server(cfg, rt, profiles, connect).new_service(Target::UNMESHED_HTTP1);
let (client, bg) = http_util::connect_and_accept(&mut client, server).await;
let (mut client, bg) = http_util::connect_and_accept_http1(&mut client, server).await;

// Send a request and assert that it is a BAD_GATEWAY with the expected
// header message.
Expand All @@ -256,7 +310,7 @@ async fn http1_bad_gateway_unmeshed_response() {
.body(Body::default())
.unwrap();
let rsp = client
.oneshot(req)
.send_request(req)
.await
.expect("HTTP client request failed");
tracing::info!(?rsp);
Expand All @@ -267,6 +321,7 @@ async fn http1_bad_gateway_unmeshed_response() {
);

// Wait for all of the background tasks to complete, panicking if any returned an error.
drop(client);
bg.join_all()
.await
.into_iter()
Expand All @@ -285,16 +340,15 @@ async fn http1_connect_timeout_meshed_response_error_header() {

// Build a client using the connect that always sleeps so that responses
// are GATEWAY_TIMEOUT.
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
let mut client = hyper::client::conn::http1::Builder::new();
let profiles = profile::resolver();
let profile_tx =
profiles.profile_tx(NameAddr::from_str_and_port("foo.svc.cluster.local", 5550).unwrap());
profile_tx.send(profile::Profile::default()).unwrap();
let cfg = default_config();
let (rt, _shutdown) = runtime();
let server = build_server(cfg, rt, profiles, connect).new_service(Target::meshed_http1());
let (client, bg) = http_util::connect_and_accept(&mut client, server).await;
let (mut client, bg) = http_util::connect_and_accept_http1(&mut client, server).await;

// Send a request and assert that it is a GATEWAY_TIMEOUT with the
// expected header message.
Expand All @@ -304,7 +358,7 @@ async fn http1_connect_timeout_meshed_response_error_header() {
.body(Body::default())
.unwrap();
let rsp = client
.oneshot(req)
.send_request(req)
.await
.expect("HTTP client request failed");
tracing::info!(?rsp);
Expand All @@ -317,6 +371,7 @@ async fn http1_connect_timeout_meshed_response_error_header() {
check_error_header(rsp.headers(), "connect timed out after 1s");

// Wait for all of the background tasks to complete, panicking if any returned an error.
drop(client);
bg.join_all()
.await
.into_iter()
Expand All @@ -335,16 +390,15 @@ async fn http1_connect_timeout_unmeshed_response_error_header() {

// Build a client using the connect that always sleeps so that responses
// are GATEWAY_TIMEOUT.
#[allow(deprecated)] // linkerd/linkerd2#8733
let mut client = hyper::client::conn::Builder::new();
let mut client = hyper::client::conn::http1::Builder::new();
let profiles = profile::resolver();
let profile_tx =
profiles.profile_tx(NameAddr::from_str_and_port("foo.svc.cluster.local", 5550).unwrap());
profile_tx.send(profile::Profile::default()).unwrap();
let cfg = default_config();
let (rt, _shutdown) = runtime();
let server = build_server(cfg, rt, profiles, connect).new_service(Target::UNMESHED_HTTP1);
let (client, bg) = http_util::connect_and_accept(&mut client, server).await;
let (mut client, bg) = http_util::connect_and_accept_http1(&mut client, server).await;

// Send a request and assert that it is a GATEWAY_TIMEOUT with the
// expected header message.
Expand All @@ -354,7 +408,7 @@ async fn http1_connect_timeout_unmeshed_response_error_header() {
.body(Body::default())
.unwrap();
let rsp = client
.oneshot(req)
.send_request(req)
.await
.expect("HTTP client request failed");
tracing::info!(?rsp);
Expand All @@ -365,6 +419,7 @@ async fn http1_connect_timeout_unmeshed_response_error_header() {
);

// Wait for all of the background tasks to complete, panicking if any returned an error.
drop(client);
bg.join_all()
.await
.into_iter()
Expand Down
45 changes: 45 additions & 0 deletions linkerd/app/test/src/http_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

/// Connects a client and server, running a proxy between them.
///
/// Returns a tuple containing (1) a [`SendRequest`] that can be used to transmit a request and

Check warning on line 14 in linkerd/app/test/src/http_util.rs

View workflow job for this annotation

GitHub Actions / rust

warning: unresolved link to `SendRequest` --> linkerd/app/test/src/http_util.rs:14:40 | 14 | /// Returns a tuple containing (1) a [`SendRequest`] that can be used to transmit a request and | ^^^^^^^^^^^ no item named `SendRequest` in scope | = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]` = note: `#[warn(rustdoc::broken_intra_doc_links)]` on by default
/// await a response, and (2) a [`JoinSet<T>`] running background tasks.
#[allow(deprecated)] // linkerd/linkerd2#8733
pub async fn connect_and_accept(
Expand Down Expand Up @@ -55,9 +55,54 @@
(client, bg)
}

/// Connects a client and server, running a proxy between them.
///
/// Returns a tuple containing (1) a [`SendRequest`] that can be used to transmit a request and

Check warning on line 60 in linkerd/app/test/src/http_util.rs

View workflow job for this annotation

GitHub Actions / rust

warning: unresolved link to `SendRequest` --> linkerd/app/test/src/http_util.rs:60:40 | 60 | /// Returns a tuple containing (1) a [`SendRequest`] that can be used to transmit a request and | ^^^^^^^^^^^ no item named `SendRequest` in scope | = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
/// await a response, and (2) a [`JoinSet<T>`] running background tasks.
pub async fn connect_and_accept_http1(
client_settings: &mut hyper::client::conn::http1::Builder,
server: BoxServer,
) -> (
hyper::client::conn::http1::SendRequest<hyper::Body>,
JoinSet<Result<(), Error>>,
) {
tracing::info!(settings = ?client_settings, "connecting client with");
let (client_io, server_io) = io::duplex(4096);

let (client, conn) = client_settings
.handshake(client_io)
.await
.expect("Client must connect");

let mut bg = tokio::task::JoinSet::new();
bg.spawn(
async move {
server
.oneshot(server_io)
.await
.map_err(ContextError::ctx("proxy background task failed"))?;
tracing::info!("proxy serve task complete");
Ok(())
}
.instrument(tracing::info_span!("proxy")),
);
bg.spawn(
async move {
conn.await
.map_err(ContextError::ctx("client background task failed"))
.map_err(Error::from)?;
tracing::info!("client background complete");
Ok(())
}
.instrument(tracing::info_span!("client_bg")),
);

(client, bg)
}

/// Connects a client and server, running a proxy between them.
///
/// Returns a tuple containing (1) a [`SendRequest`] that can be used to transmit a request and

Check warning on line 105 in linkerd/app/test/src/http_util.rs

View workflow job for this annotation

GitHub Actions / rust

warning: unresolved link to `SendRequest` --> linkerd/app/test/src/http_util.rs:105:40 | 105 | /// Returns a tuple containing (1) a [`SendRequest`] that can be used to transmit a request and | ^^^^^^^^^^^ no item named `SendRequest` in scope | = help: to escape `[` and `]` characters, add '\' before them like `\[` or `\]`
/// await a response, and (2) a [`JoinSet<T>`] running background tasks.
pub async fn connect_and_accept_http2<B>(
client_settings: &mut hyper::client::conn::http2::Builder,
Expand Down
Loading