Skip to content

Commit

Permalink
wip
Browse files Browse the repository at this point in the history
  • Loading branch information
olix0r committed Jul 26, 2024
1 parent e644815 commit 4c882ba
Show file tree
Hide file tree
Showing 2 changed files with 137 additions and 0 deletions.
1 change: 1 addition & 0 deletions linkerd/app/outbound/src/http/logical/tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ use tracing::Instrument;

mod basic;
mod failure_accrual;
mod headers;
mod retries;
mod timeouts;

Expand Down
136 changes: 136 additions & 0 deletions linkerd/app/outbound/src/http/logical/tests/headers.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
use super::*;
use linkerd_app_core::{proxy::http::StatusCode, trace};
use linkerd_proxy_client_policy::http::RouteParams as HttpParams;
use tokio::time;
use tracing::{info, Instrument};

#[tokio::test(flavor = "current_thread", start_paused = true)]
async fn http() {
let _trace = trace::test::trace_init();

const TIMEOUT: time::Duration = time::Duration::from_secs(2);
let (svc, mut handle) = mock_http(HttpParams {
allow_l5d_request_headers: true,
..Default::default()
});

info!("Sending a request that will initially fail and then succeed");
tokio::spawn(
async move {
handle.allow(2);
info!("Failing the first request");
serve(&mut handle, mk_rsp(StatusCode::INTERNAL_SERVER_ERROR, "")).await;
info!("Serving the second request");
serve(&mut handle, mk_rsp(StatusCode::NO_CONTENT, "")).await;
handle
}
.in_current_span(),
);

info!("Verifying that we see the successful response");
let rsp = time::timeout(
TIMEOUT,
send_req(
svc.clone(),
http::Request::get("/")
.header("l5d-retry-limit", "1")
.header("l5d-retry-http", "5xx")
.header("l5d-retry-timeout", "100ms")
.body(Default::default())
.unwrap(),
),
)
.await
.expect("response");
assert_eq!(rsp.expect("response").status(), StatusCode::NO_CONTENT);
}

#[tokio::test(flavor = "current_thread", start_paused = true)]
async fn http_5xx_limited() {
let _trace = trace::test::trace_init();

const TIMEOUT: time::Duration = time::Duration::from_secs(2);
let (svc, mut handle) = mock_http(HttpParams {
allow_l5d_request_headers: true,
..Default::default()
});

tokio::spawn(
async move {
handle.allow(3);
info!("Failing the first request");
serve(&mut handle, mk_rsp(StatusCode::INTERNAL_SERVER_ERROR, "")).await;
info!("Failing the second request");
serve(&mut handle, mk_rsp(StatusCode::GATEWAY_TIMEOUT, "")).await;
info!("Failing the third request");
serve(&mut handle, mk_rsp(StatusCode::INSUFFICIENT_STORAGE, "")).await;
info!("Prepping the fourth request (shouldn't be served)");
serve(&mut handle, mk_rsp(StatusCode::NO_CONTENT, "")).await;
handle
}
.in_current_span(),
);

info!("Sending a request that will initially fail and then succeed");
let rsp = time::timeout(
TIMEOUT,
send_req(
svc.clone(),
http::Request::get("/")
.header("l5d-retry-limit", "2")
.header("l5d-retry-http", "5xx")
.body(Default::default())
.unwrap(),
),
)
.await
.expect("response");

info!("Verifying that we see a failure");
assert_eq!(
rsp.expect("response").status(),
StatusCode::INSUFFICIENT_STORAGE
);
}

#[tokio::test(flavor = "current_thread", start_paused = true)]
async fn http_5xx_requires_allow() {
let _trace = trace::test::trace_init();

const TIMEOUT: time::Duration = time::Duration::from_secs(2);
let (svc, mut handle) = mock_http(HttpParams {
allow_l5d_request_headers: false,
..Default::default()
});

tokio::spawn(
async move {
handle.allow(2);
serve(&mut handle, mk_rsp(StatusCode::INTERNAL_SERVER_ERROR, "")).await;
serve(&mut handle, mk_rsp(StatusCode::NO_CONTENT, "")).await;
handle
}
.in_current_span(),
);

info!("Sending a request that will initially fail and then succeed");
let rsp = time::timeout(
TIMEOUT,
send_req(
svc.clone(),
http::Request::get("/")
.header("l5d-retry-limit", "1")
.header("l5d-retry-http", "5xx")
.body(Default::default())
.unwrap(),
),
)
.await
.expect("response");

info!("Verifying that we see the successful response");
assert_eq!(
rsp.expect("response").status(),
StatusCode::INTERNAL_SERVER_ERROR
);
}

0 comments on commit 4c882ba

Please sign in to comment.