Skip to content

Commit 67b4d41

Browse files
authored
refactor(app/integration): forward-compatible test code (#3673)
see linkerd/linkerd2#8733 for more information. see #3559 and #3614 for more information on the `ForwardCompatibleBody<B>` wrapper. this branch updates test code in `linkerd-app-integration` so that it interacts with request and response bodies via an adapter that polls for frames in a manner consistent with the 1.0 api of `http_body`. this allows us to limit the diff in #3504, which will only need to remove this adapter once using hyper 1.0. see #3671 and #3672, which perform the same change for `linkerd-app-inbound` and `linkerd-app-outbound`, respectively. --- * chore(app/integration): `linkerd-http-body-compat` test dependency Signed-off-by: katelyn martin <[email protected]> * refactor(app/integration): generalize `hyper::Body` Signed-off-by: katelyn martin <[email protected]> * refactor(app/integration): use `ForwardCompatibleBody` Signed-off-by: katelyn martin <[email protected]> --------- Signed-off-by: katelyn martin <[email protected]>
1 parent f934c80 commit 67b4d41

File tree

3 files changed

+36
-11
lines changed

3 files changed

+36
-11
lines changed

Cargo.lock

+1
Original file line numberDiff line numberDiff line change
@@ -1481,6 +1481,7 @@ dependencies = [
14811481
"linkerd-app-admin",
14821482
"linkerd-app-core",
14831483
"linkerd-app-test",
1484+
"linkerd-http-body-compat",
14841485
"linkerd-meshtls",
14851486
"linkerd-metrics",
14861487
"linkerd-tracing",

linkerd/app/integration/Cargo.toml

+1
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,7 @@ flate2 = { version = "1", default-features = false, features = [
6363
] }
6464
# Log streaming isn't enabled by default globally, but we want to test it.
6565
linkerd-app-admin = { path = "../admin", features = ["log-streaming"] }
66+
linkerd-http-body-compat = { path = "../../http/body-compat" }
6667
# No code from this crate is actually used; only necessary to enable the Rustls
6768
# implementation.
6869
linkerd-meshtls = { path = "../../meshtls", features = ["rustls"] }

linkerd/app/integration/src/tests/profiles.rs

+34-11
Original file line numberDiff line numberDiff line change
@@ -682,7 +682,9 @@ mod grpc_retry {
682682
assert_eq!(res.status(), 200);
683683
assert_eq!(res.headers().get(&GRPC_STATUS), None);
684684

685-
let mut body = res.into_body();
685+
let mut body = res
686+
.map(linkerd_http_body_compat::ForwardCompatibleBody::new)
687+
.into_body();
686688
let trailers = trailers(&mut body).await;
687689
assert_eq!(trailers.get(&GRPC_STATUS), Some(&GRPC_STATUS_OK));
688690
assert_eq!(retries.load(Ordering::Relaxed), 2);
@@ -726,7 +728,9 @@ mod grpc_retry {
726728
assert_eq!(res.status(), 200);
727729
assert_eq!(res.headers().get(&GRPC_STATUS), None);
728730

729-
let mut body = res.into_body();
731+
let mut body = res
732+
.map(linkerd_http_body_compat::ForwardCompatibleBody::new)
733+
.into_body();
730734

731735
let data = data(&mut body).await;
732736
assert_eq!(data, Bytes::from("hello world"));
@@ -777,7 +781,9 @@ mod grpc_retry {
777781
assert_eq!(res.status(), 200);
778782
assert_eq!(res.headers().get(&GRPC_STATUS), None);
779783

780-
let mut body = res.into_body();
784+
let mut body = res
785+
.map(linkerd_http_body_compat::ForwardCompatibleBody::new)
786+
.into_body();
781787

782788
let frame1 = data(&mut body).await;
783789
assert_eq!(frame1, Bytes::from("hello"));
@@ -790,21 +796,38 @@ mod grpc_retry {
790796
assert_eq!(retries.load(Ordering::Relaxed), 1);
791797
}
792798

793-
async fn data(body: &mut hyper::Body) -> Bytes {
799+
async fn data<B>(body: &mut linkerd_http_body_compat::ForwardCompatibleBody<B>) -> B::Data
800+
where
801+
B: http_body::Body + Unpin,
802+
B::Data: std::fmt::Debug,
803+
B::Error: std::fmt::Debug,
804+
{
794805
let data = body
795-
.data()
806+
.frame()
796807
.await
797-
.expect("body data frame must not be eaten")
798-
.unwrap();
808+
.expect("a result")
809+
.expect("a frame")
810+
.into_data()
811+
.expect("a chunk of data");
799812
tracing::info!(?data);
800813
data
801814
}
802-
async fn trailers(body: &mut hyper::Body) -> http::HeaderMap {
815+
816+
async fn trailers<B>(
817+
body: &mut linkerd_http_body_compat::ForwardCompatibleBody<B>,
818+
) -> http::HeaderMap
819+
where
820+
B: http_body::Body + Unpin,
821+
B::Error: std::fmt::Debug,
822+
{
803823
let trailers = body
804-
.trailers()
824+
.frame()
805825
.await
806-
.expect("trailers future should not fail")
807-
.expect("response should have trailers");
826+
.expect("a result")
827+
.expect("a frame")
828+
.into_trailers()
829+
.ok()
830+
.expect("a trailers frame");
808831
tracing::info!(?trailers);
809832
trailers
810833
}

0 commit comments

Comments
 (0)