Skip to content

Commit 68fb7dc

Browse files
committed
add a timeout to each individual request in tests
1 parent 756c023 commit 68fb7dc

File tree

2 files changed

+11
-5
lines changed

2 files changed

+11
-5
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ jobs:
5555
run: docker compose logs ${{ matrix.database }}
5656
- name: Run tests against ${{ matrix.database }}
5757
timeout-minutes: 5
58-
run: cargo test -- --nocapture
58+
run: cargo test
5959
env:
6060
DATABASE_URL: ${{ matrix.database }}://root:Password123!@127.0.0.1/sqlpage
6161
RUST_BACKTRACE: 1

tests/index.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ async fn test_files() {
183183
let req_str = format!("/{}?x=1", test_file_path_string);
184184
let resp = req_path_with_app_data(&req_str, app_data.clone())
185185
.await
186-
.unwrap_or_else(|_| panic!("Failed to get response for {req_str}"));
186+
.unwrap_or_else(|e| panic!("Failed to get response for {req_str}: {e}"));
187187
let body = test::read_body(resp).await;
188188
assert!(
189189
body.starts_with(b"<!DOCTYPE html>"),
@@ -607,7 +607,7 @@ async fn test_official_website_documentation() {
607607
let app_data = make_app_data_for_official_website().await;
608608
let resp = req_path_with_app_data("/component.sql?component=button", app_data)
609609
.await
610-
.unwrap();
610+
.unwrap_or_else(|e| panic!("Failed to get response for /component.sql?component=button: {e}"));
611611
assert_eq!(resp.status(), http::StatusCode::OK);
612612
let body = test::read_body(resp).await;
613613
let body_str = String::from_utf8(body.to_vec()).unwrap();
@@ -681,12 +681,18 @@ async fn srv_req_path_with_app_data(
681681
.to_srv_request()
682682
}
683683

684+
const REQ_TIMEOUT: std::time::Duration = std::time::Duration::from_secs(3);
684685
async fn req_path_with_app_data(
685686
path: impl AsRef<str>,
686687
app_data: actix_web::web::Data<AppState>,
687-
) -> Result<actix_web::dev::ServiceResponse, actix_web::Error> {
688+
) -> anyhow::Result<actix_web::dev::ServiceResponse> {
689+
let path = path.as_ref();
688690
let req = srv_req_path_with_app_data(path, app_data).await;
689-
main_handler(req).await
691+
let resp = tokio::time::timeout(REQ_TIMEOUT, main_handler(req))
692+
.await
693+
.map_err(|e| anyhow::anyhow!("Request to {path} timed out: {e}"))?
694+
.map_err(|e| anyhow::anyhow!("Request to {path} failed: {e}"))?;
695+
Ok(resp)
690696
}
691697

692698
pub fn test_config() -> AppConfig {

0 commit comments

Comments
 (0)