-
Notifications
You must be signed in to change notification settings - Fork 271
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
2 changed files
with
137 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -14,6 +14,7 @@ use tracing::Instrument; | |
|
||
mod basic; | ||
mod failure_accrual; | ||
mod headers; | ||
mod retries; | ||
mod timeouts; | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
); | ||
} |