Skip to content

Commit

Permalink
refactor(app/test): minor tweaks to linkerd-app-test (#3428)
Browse files Browse the repository at this point in the history
while handling the upgrade to hyper 1.0, i noticed some small changes
that'd be nice to make.

most importantly, with respect to
linkerd/linkerd2#8733, this commit outlines
`http_util::http_request()`. hyper 1.0 provides version specific
`SendRequest` types for HTTP/1 and HTTP/2, so rather than try to be
polymorphic across both senders, we send the request at the call site.

two other commits remove `pub` attributes for functions that aren't
called externally. we'll address `run_proxy()` and `connect_client()` in
a subsequent PR, because the dependent tests use both HTTP/1 and HTTP/2. 

---

* refactor(app/test): remove `pub` from `http_util::connect_client()`

this is not used elsewhere. it can be private.

Signed-off-by: katelyn martin <kate@buoyant.io>

* refactor(app/test): remove `pub` from `http_util::run_proxy()`

Signed-off-by: katelyn martin <kate@buoyant.io>

* refactor(app/test): remove `http_util::http_request()`

this function abstracts over one statement, at the cost of needing to
name the `SendRequest` type.

because hyper's 1.0 interface provides multiple `SendRequest` types
based on the HTTP version being used. to avoid needing to deal with
polymorphism, and to implicitly address a function-level allowance of
deprecated types, we remove this function and move this statement to the
function's call sites.

Signed-off-by: katelyn martin <kate@buoyant.io>

* refactor(app/test): collect bodies with `String::from_utf8`

this function previously called `std::str::from_utf8`, before calling
`str::to_owned` on the result. because of this, there is a bit of extra
gymnastics, passing a `&body[..]` slice along after collecting the body
bytes.

this is both more baroque and less performant. this commit updates the
call, using `String::from_utf8` to collect the body, sparing a needless
`to_owned()`/`clone()` call.

Signed-off-by: katelyn martin <kate@buoyant.io>

* docs(app/test): document `io` submodule

Signed-off-by: katelyn martin <kate@buoyant.io>

* refactor(app/test): remove duplicate `io` reëxport

the same `pub use` bundle is found in the parent `lib.rs`.

this removes it, and refers to the same `mod io {}` defined above.

Signed-off-by: katelyn martin <kate@buoyant.io>

* review(app/inbound): use `ServiceExt::oneshot(..)`

#3428 (comment)

we can simplify these statements sending requests, by using
`ServiceExt::oneshot(..)`.

Signed-off-by: katelyn martin <kate@buoyant.io>

---------

Signed-off-by: katelyn martin <kate@buoyant.io>
  • Loading branch information
cratelyn authored Dec 6, 2024
1 parent 2989101 commit a39eb30
Show file tree
Hide file tree
Showing 5 changed files with 117 additions and 89 deletions.
9 changes: 8 additions & 1 deletion linkerd/app/inbound/src/http.rs
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,14 @@ pub mod fuzz {
.header(header_name, header_value)
.body(Body::default())
{
let rsp = http_util::http_request(&mut client, req).await;
let rsp = client
.ready()
.await
.expect("HTTP client poll_ready failed")
.call(req)
.await
.expect("HTTP client request failed");
tracing::info!(?rsp);
tracing::info!(?rsp);
if let Ok(rsp) = rsp {
let body = http_util::body_to_string(rsp.into_body()).await;
Expand Down
Loading

0 comments on commit a39eb30

Please sign in to comment.