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(app/test): address hyper deprecations in test helpers #3433

Merged
merged 10 commits into from
Dec 9, 2024

Conversation

cratelyn
Copy link
Collaborator

@cratelyn cratelyn commented Dec 7, 2024

this commit changes the connect_and_accept(..) helper function used in
the proxy's unit tests, altering its logic such that it now runs
background tasks inside of a JoinSet.

then, subsequent commits hoist code out of run_proxy() and connect_client(), and consolidate our async move {} blocks. this both simplifies the control flow of this test infrastructure, but also addresses some more hyper deprecations.

for more information about our progressing upgrade to hyper 1.0, see linkerd/linkerd2#8733.

NB: this branch is based upon #3432.

this was not being flagged as an unused variable, due to the
`#[instrument]` attribute. (😉 _it's used as a field in the generated
span!_)

`connect_timeout(..)` doesn't use its parameter.

to address some deprecations, and avoid the need for polymorphism /
refactoring related to http/1 and http/2 connections being represented
as distinct types in the hyper 1.0 api, we remove it.

Signed-off-by: katelyn martin <kate@buoyant.io>
this addresses hyper 1.0 deprecations in the server side of the inbound
proxy's http unit test suite logic.

see <linkerd/linkerd2#8733> for more
information.

the client end of this change ends up being slightly involved, due to
changes that will need to be made in `linkerd_app_test::http_util`.
accordingly, those deprecations will be addressed in a subsequent
commit.

Signed-off-by: katelyn martin <kate@buoyant.io>
this moves the public `connect_client(..)` function up to the top of the
group of functions, and adds a documentation comment explaining its
purpose.

a todo comment is left noting that this can be refactored to use tokio's
new `JoinSet` type.

Signed-off-by: katelyn martin <kate@buoyant.io>
this is a small tweak, defering the call to `tokio::spawn(..)` to make
using `JoinSet` easier.

Signed-off-by: katelyn martin <kate@buoyant.io>
this commit changes the `connect_and_accept(..)` helper function used in
the proxy's unit tests, altering its logic such that it now runs
background tasks inside of a `JoinSet`.

Signed-off-by: katelyn martin <kate@buoyant.io>
this commit makes two minor changes to the `run_proxy()` helper
function:

* remove a frivolous `.map(|_| ())` on a result that already had a tuple
  `Ok` type.

* use `ServiceExt::oneshot` for brevity.

this should have no effect on the tests, we're just golfing things down
a bit.

Signed-off-by: katelyn martin <kate@buoyant.io>
Signed-off-by: katelyn martin <kate@buoyant.io>
@cratelyn cratelyn marked this pull request as ready for review December 7, 2024 01:14
@cratelyn cratelyn requested a review from a team as a code owner December 7, 2024 01:14
we've nudged this along well enough that this function can now
reasonably be removed.

Signed-off-by: katelyn martin <kate@buoyant.io>
and once more, we remove a helper function that isn't doing quite so
much work, and whose signature contains deprecated hyper 1.0 types.

Signed-off-by: katelyn martin <kate@buoyant.io>
@cratelyn cratelyn marked this pull request as draft December 7, 2024 01:32
we create `async move {}` blocks in multiple places, without any clear
benefit.

this commit consolidates them into one place: when we spawn a task onto
the `JoinSet`.

Signed-off-by: katelyn martin <kate@buoyant.io>
@cratelyn cratelyn force-pushed the kate/hyper-1.x-app-inbound-test-updates.part-2 branch from 4a06bf8 to ae3cca2 Compare December 7, 2024 01:41
@cratelyn cratelyn changed the title refactor(app/test): use JoinSet for background tasks refactor(app/test): address hyper deprecations in test helpers Dec 7, 2024
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the diff in this file is much more easily reviewed on a commit by commit basis.

@cratelyn cratelyn marked this pull request as ready for review December 7, 2024 01:49
bg.join_all()
.await
.into_iter()
.collect::<Result<Vec<()>, Error>>()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If you want, you can use core::Result so this is just .collect::<Result<Vec<()>>>()

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i took a swing at this, but i think i'll opt to elide this.

i have a personal aversion to importing Result aliases that overwrite the Result<T, E> included in the standard prelude, and found that the alternate .collect::<linkerd_app_core::Result<Vec<()>>>() form didn't really golf this down much.

#[allow(deprecated)] // linkerd/linkerd2#8733
async fn connect_client(
pub async fn connect_and_accept(
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can the above deprecation be removed yet?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

not quite yet, https://github.com/linkerd/linkerd2-proxy/pull/3433/files/ae3cca22f0219533bd3b8f59b81fb0f1e852ddcf#diff-8cdd5a92a26923db556253828b546a6741d66ed6e5be3ba2043b535d8e34695dR11 the ClientBuilder parameter to this function is still a deprecated connection builder type.

this is definitely next on the chopping block though 🗡️ 😈

Base automatically changed from kate/hyper-1.x-app-inbound-test-updates.part-1 to main December 9, 2024 16:55
@cratelyn cratelyn merged commit d65fe07 into main Dec 9, 2024
15 checks passed
@cratelyn cratelyn deleted the kate/hyper-1.x-app-inbound-test-updates.part-2 branch December 9, 2024 19:44
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.

2 participants