Skip to content

Commit 1eb822f

Browse files
authored
refactor(http/retry): port some ReplayBody tests to Frame<T> (#3564)
see linkerd/linkerd2#8733. pr #3559 introduced some compatibility facilities to allow us to write code in terms of `http_body_util::BodyExt::frame()`, front-running the upgrade to be performed in #3504. some `ReplayBody` tests use the defunct `data()` and `trailers()` interfaces. this branch ports _two_ such unit tests. other tests are saved for a fast follow-on, as the `chunk(..)` and `read_to_string(..)` helpers will need some slightly more involved tweaks. dd4fbcd --- * refactor(http/retry): `replays_trailers()` uses `Frame<T>` see linkerd/linkerd2#8733. this commit upgrades a test that uses defunct `data()` and `trailers()` futures. Signed-off-by: katelyn martin <[email protected]> * refactor(http/retry): `trailers_only()` uses `Frame<T>` see linkerd/linkerd2#8733. this commit upgrades a test that uses defunct `data()` and `trailers()` futures. Signed-off-by: katelyn martin <[email protected]> --------- Signed-off-by: katelyn martin <[email protected]>
1 parent 0484917 commit 1eb822f

File tree

1 file changed

+45
-22
lines changed

1 file changed

+45
-22
lines changed

linkerd/http/retry/src/replay.rs

Lines changed: 45 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -547,8 +547,8 @@ mod tests {
547547
async fn replays_trailers() {
548548
let Test {
549549
mut tx,
550-
mut initial,
551-
mut replay,
550+
initial,
551+
replay,
552552
_trace,
553553
} = Test::new();
554554

@@ -560,30 +560,43 @@ mod tests {
560560
tx.send_trailers(tlrs.clone()).await;
561561
drop(tx);
562562

563-
while initial.data().await.is_some() {
564-
// do nothing
565-
}
566-
let initial_tlrs = initial.trailers().await.expect("trailers should not error");
567-
assert_eq!(initial_tlrs.as_ref(), Some(&tlrs));
563+
let read_trailers = |body: ReplayBody<_>| async move {
564+
let mut body = crate::compat::ForwardCompatibleBody::new(body);
565+
let _ = body
566+
.frame()
567+
.await
568+
.expect("should yield a result")
569+
.expect("should yield a frame")
570+
.into_data()
571+
.expect("should yield data");
572+
let trls = body
573+
.frame()
574+
.await
575+
.expect("should yield a result")
576+
.expect("should yield a frame")
577+
.into_trailers()
578+
.expect("should yield trailers");
579+
assert!(body.frame().await.is_none());
580+
trls
581+
};
568582

569-
// drop the initial body to send the data to the replay
570-
drop(initial);
583+
let initial_tlrs = read_trailers(initial).await;
584+
assert_eq!(&initial_tlrs, &tlrs);
571585

572-
while replay.data().await.is_some() {
573-
// do nothing
574-
}
575-
let replay_tlrs = replay.trailers().await.expect("trailers should not error");
576-
assert_eq!(replay_tlrs.as_ref(), Some(&tlrs));
586+
let replay_tlrs = read_trailers(replay).await;
587+
assert_eq!(&replay_tlrs, &tlrs);
577588
}
578589

579590
#[tokio::test]
580591
async fn trailers_only() {
581592
let Test {
582593
mut tx,
583-
mut initial,
584-
mut replay,
594+
initial,
595+
replay,
585596
_trace,
586597
} = Test::new();
598+
let mut initial = crate::compat::ForwardCompatibleBody::new(initial);
599+
let mut replay = crate::compat::ForwardCompatibleBody::new(replay);
587600

588601
let mut tlrs = HeaderMap::new();
589602
tlrs.insert("x-hello", HeaderValue::from_str("world").unwrap());
@@ -593,16 +606,26 @@ mod tests {
593606

594607
drop(tx);
595608

596-
assert!(dbg!(initial.data().await).is_none(), "no data in body");
597-
let initial_tlrs = initial.trailers().await.expect("trailers should not error");
598-
assert_eq!(initial_tlrs.as_ref(), Some(&tlrs));
609+
let initial_tlrs = initial
610+
.frame()
611+
.await
612+
.expect("should yield a result")
613+
.expect("should yield a frame")
614+
.into_trailers()
615+
.expect("should yield trailers");
616+
assert_eq!(&initial_tlrs, &tlrs);
599617

600618
// drop the initial body to send the data to the replay
601619
drop(initial);
602620

603-
assert!(dbg!(replay.data().await).is_none(), "no data in body");
604-
let replay_tlrs = replay.trailers().await.expect("trailers should not error");
605-
assert_eq!(replay_tlrs.as_ref(), Some(&tlrs));
621+
let replay_tlrs = replay
622+
.frame()
623+
.await
624+
.expect("should yield a result")
625+
.expect("should yield a frame")
626+
.into_trailers()
627+
.expect("should yield trailers");
628+
assert_eq!(&replay_tlrs, &tlrs);
606629
}
607630

608631
#[tokio::test(flavor = "current_thread")]

0 commit comments

Comments
 (0)