Skip to content

Commit 4a06bf8

Browse files
committed
refactor(app/test): consolidate anonymous futures
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]>
1 parent 15d1b09 commit 4a06bf8

File tree

1 file changed

+9
-15
lines changed

1 file changed

+9
-15
lines changed

linkerd/app/test/src/http_util.rs

Lines changed: 9 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ use crate::{
22
app_core::{svc, Error},
33
io, ContextError,
44
};
5-
use futures::FutureExt;
65
use hyper::{body::HttpBody, Body};
76
use tokio::task::JoinSet;
87
use tower::ServiceExt;
@@ -24,37 +23,32 @@ pub async fn connect_and_accept(
2423
) -> (SendRequest<Body>, JoinSet<Result<(), Error>>) {
2524
tracing::info!(settings = ?client_settings, "connecting client with");
2625
let (client_io, server_io) = io::duplex(4096);
27-
let proxy = async move {
28-
let res = server.oneshot(server_io).await;
29-
tracing::info!(?res, "proxy serve task complete");
30-
res
31-
};
3226

3327
let (client, conn) = client_settings
3428
.handshake(client_io)
3529
.await
3630
.expect("Client must connect");
37-
let client_bg = conn.map(|res| {
38-
tracing::info!(?res, "Client background complete");
39-
res.map_err(Error::from)
40-
});
4131

4232
let mut bg = tokio::task::JoinSet::new();
4333
bg.spawn(
4434
async move {
45-
proxy
35+
let res = server
36+
.oneshot(server_io)
4637
.await
47-
.map_err(ContextError::ctx("proxy background task failed"))
48-
.map_err(Error::from)
38+
.map_err(ContextError::ctx("proxy background task failed"))?;
39+
tracing::info!(?res, "proxy serve task complete");
40+
Ok(())
4941
}
5042
.instrument(tracing::info_span!("proxy")),
5143
);
5244
bg.spawn(
5345
async move {
54-
client_bg
46+
let res = conn
5547
.await
5648
.map_err(ContextError::ctx("client background task failed"))
57-
.map_err(Error::from)
49+
.map_err(Error::from)?;
50+
tracing::info!(?res, "client background complete");
51+
Ok(())
5852
}
5953
.instrument(tracing::info_span!("client_bg")),
6054
);

0 commit comments

Comments
 (0)