Skip to content

Commit

Permalink
refactor(app/test): consolidate anonymous futures
Browse files Browse the repository at this point in the history
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 <[email protected]>
  • Loading branch information
cratelyn committed Dec 7, 2024
1 parent 15d1b09 commit ae3cca2
Showing 1 changed file with 9 additions and 16 deletions.
25 changes: 9 additions & 16 deletions linkerd/app/test/src/http_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ use crate::{
app_core::{svc, Error},
io, ContextError,
};
use futures::FutureExt;
use hyper::{body::HttpBody, Body};
use tokio::task::JoinSet;
use tower::ServiceExt;
Expand All @@ -24,37 +23,31 @@ pub async fn connect_and_accept(
) -> (SendRequest<Body>, JoinSet<Result<(), Error>>) {
tracing::info!(settings = ?client_settings, "connecting client with");
let (client_io, server_io) = io::duplex(4096);
let proxy = async move {
let res = server.oneshot(server_io).await;
tracing::info!(?res, "proxy serve task complete");
res
};

let (client, conn) = client_settings
.handshake(client_io)
.await
.expect("Client must connect");
let client_bg = conn.map(|res| {
tracing::info!(?res, "Client background complete");
res.map_err(Error::from)
});

let mut bg = tokio::task::JoinSet::new();
bg.spawn(
async move {
proxy
server
.oneshot(server_io)
.await
.map_err(ContextError::ctx("proxy background task failed"))
.map_err(Error::from)
.map_err(ContextError::ctx("proxy background task failed"))?;
tracing::info!("proxy serve task complete");
Ok(())
}
.instrument(tracing::info_span!("proxy")),
);
bg.spawn(
async move {
client_bg
.await
conn.await
.map_err(ContextError::ctx("client background task failed"))
.map_err(Error::from)
.map_err(Error::from)?;
tracing::info!("client background complete");
Ok(())
}
.instrument(tracing::info_span!("client_bg")),
);
Expand Down

0 comments on commit ae3cca2

Please sign in to comment.