Skip to content
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

refactor(mock/http-body): outline MockBody test body #3611

Merged
merged 1 commit into from
Feb 12, 2025

Conversation

cratelyn
Copy link
Collaborator

MockBody is a type that we use to implement tests for our peek_trailers::PeekTrailersBody<B> body middleware. this is a useful tool for mocking the polling outcomes of the inner body we wrap, which would be useful for testing other http_body::Body middleware.

this commit moves MockBody out of linkerd-http-retry, and into a new linkerd-mock-http-body crate. this is added as a test dependency for the retry crate, and can now be used (rather than vendored) by other bodies.

`MockBody` is a type that we use to implement tests for our
`peek_trailers::PeekTrailersBody<B>` body middleware. this is a useful
tool for mocking the polling outcomes of the inner body we wrap, which
would be useful for testing other `http_body::Body` middleware.

this commit moves `MockBody` out of `linkerd-http-retry`, and into a new
`linkerd-mock-http-body` crate. this is added as a test dependency for
the retry crate, and can now be used (rather than vendored) by other
bodies.

Signed-off-by: katelyn martin <[email protected]>
@cratelyn cratelyn force-pushed the kate/mock-http-body branch from 2428926 to c0ad90b Compare February 12, 2025 03:43
@cratelyn cratelyn marked this pull request as ready for review February 12, 2025 03:52
@cratelyn cratelyn requested a review from a team as a code owner February 12, 2025 03:52
@olix0r olix0r merged commit b2e8623 into main Feb 12, 2025
16 checks passed
@olix0r olix0r deleted the kate/mock-http-body branch February 12, 2025 15:14
cratelyn added a commit that referenced this pull request Feb 14, 2025
this commit makes some minor alterations to our error recovery body
middleware. see linkerd/linkerd2#8733 for more
information.

this commit removes an `assert!` statement from the implementation of
`<Response<R, B> as Body>::poll_data()`. see the documentation of
`Body::poll_frame()`:

> Once the end of the stream is reached, implementations should
> continue to return [`Poll::Ready(None)`].

hyperium/http-body@1090bff#diff-33aabe8c2aaa7614022addf244245e09bbff576a67a9ae3c6938c8a868201d36R60-R61

to do this, this commit introduces a distinct terminal state
`Inner::Rescued` to represent when the underlying `B`-typed body has
yielded an error and been rescued. once in this state the body will
yield no more data frames, instead yielding a collection of trailers
describing the mid-stream error that was encountered by the underlying
body.

the call to `R::rescue` is also moved down into the helper function fka
`grpc_trailers()`. this helps the function follow the grain of our
"state machine" a little more directly.

see #3615, #3614, and #3611 for pretext to this change.
cratelyn added a commit that referenced this pull request Feb 14, 2025
this commit makes some minor alterations to our error recovery body
middleware. see linkerd/linkerd2#8733 for more
information.

this commit removes an `assert!` statement from the implementation of
`<Response<R, B> as Body>::poll_data()`. see the documentation of
`Body::poll_frame()`:

> Once the end of the stream is reached, implementations should
> continue to return [`Poll::Ready(None)`].

hyperium/http-body@1090bff#diff-33aabe8c2aaa7614022addf244245e09bbff576a67a9ae3c6938c8a868201d36R60-R61

to do this, this commit introduces a distinct terminal state
`Inner::Rescued` to represent when the underlying `B`-typed body has
yielded an error and been rescued. once in this state the body will
yield no more data frames, instead yielding a collection of trailers
describing the mid-stream error that was encountered by the underlying
body.

the call to `R::rescue` is also moved down into the helper function fka
`grpc_trailers()`. this helps the function follow the grain of our
"state machine" a little more directly.

see #3615, #3614, and #3611 for pretext to this change.

Signed-off-by: katelyn martin <[email protected]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants