Skip to content

Commit

Permalink
add GET timeout to mirror tests (#3642)
Browse files Browse the repository at this point in the history
  • Loading branch information
LesnyRumcajs authored Oct 31, 2023
1 parent 2440893 commit f04adb8
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .config/nextest.toml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ slow-timeout = { period = "120s", terminate-after = 3 }
# It is only run on CI, so we can afford to be more patient.
[[profile.default.overrides]]
filter = 'test(networks::actors_bundle::tests::check_bundles_are_mirrored)'
slow-timeout = { period = "60s", terminate-after = 3 }
slow-timeout = { period = "120s", terminate-after = 3 }

[[profile.default.overrides]]
# lint runs `cargo check` for source file discovery, which can take a while
Expand Down
25 changes: 19 additions & 6 deletions src/networks/actors_bundle.rs
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,7 @@ pub async fn generate_actor_bundle(output: &Path) -> anyhow::Result<()> {
mod tests {
use http::StatusCode;
use reqwest::Response;
use std::time::Duration;

use crate::utils::net::global_http_client;

Expand All @@ -149,8 +150,12 @@ mod tests {
url,
alt_url,
}| async move {
let primary = http_get(url).await;
let alt = http_get(alt_url).await;
let (primary, alt) = match (http_get(url).await, http_get(alt_url).await) {
(Ok(primary), Ok(alt)) => (primary, alt),
(Err(_), Err(_)) => anyhow::bail!("Both sources are down"),
// If either of the sources are otherwise down, we don't want to fail the test.
_ => return anyhow::Ok(()),
};

// Check that neither of the sources respond with 404.
// Such code would indicate that the bundle URLs are incorrect.
Expand All @@ -176,8 +181,12 @@ mod tests {
// Check that the bundles are identical.
// This is to ensure that the bundle was not tamperered with and that the
// bundle was uploaded to the alternative URL correctly.
let primary = primary.bytes().await?;
let alt = alt.bytes().await?;
let (primary, alt) = match (primary.bytes().await, alt.bytes().await) {
(Ok(primary), Ok(alt)) => (primary, alt),
(Err(_), Err(_)) => anyhow::bail!("Both sources are down"),
// If either of the sources are otherwise down, we don't want to fail the test.
_ => return anyhow::Ok(()),
};

let car_primary = CarStream::new(Cursor::new(primary)).await?;
let car_secondary = CarStream::new(Cursor::new(alt)).await?;
Expand All @@ -199,7 +208,11 @@ mod tests {
.unwrap();
}

pub async fn http_get(url: &Url) -> Response {
global_http_client().get(url.clone()).send().await.unwrap()
pub async fn http_get(url: &Url) -> anyhow::Result<Response> {
Ok(global_http_client()
.get(url.clone())
.timeout(Duration::from_secs(120))
.send()
.await?)
}
}

0 comments on commit f04adb8

Please sign in to comment.