Skip to content

Commit

Permalink
fix(test): timeout in rpc_regression_tests (#5153)
Browse files Browse the repository at this point in the history
  • Loading branch information
hanabi1224 authored Jan 20, 2025
1 parent 1a9f978 commit 3bae32a
Showing 1 changed file with 30 additions and 21 deletions.
51 changes: 30 additions & 21 deletions src/tool/subcommands/api_cmd/test_snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,7 @@ mod tests {
use super::*;
use crate::{daemon::db_util::download_to, utils::net::global_http_client};
use directories::ProjectDirs;
use futures::{stream::FuturesUnordered, StreamExt};
use itertools::Itertools as _;
use md5::{Digest as _, Md5};
use url::Url;
Expand All @@ -156,38 +157,46 @@ mod tests {
.split("\n")
.filter_map(|n| {
Url::parse(
format!("https://forest-snapshots.fra1.digitaloceanspaces.com/rpc_test/{n}")
.as_str(),
format!(
"https://forest-snapshots.fra1.cdn.digitaloceanspaces.com/rpc_test/{n}"
)
.as_str(),
)
.ok()
.map(|url| (n, url))
})
.collect_vec();
let project_dir = ProjectDirs::from("com", "ChainSafe", "Forest").unwrap();
let cache_dir = project_dir.cache_dir().join("test").join("rpc-snapshots");
for (filename, url) in urls {
let cache_file_path = cache_dir.join(filename);
let is_file_cached = match get_file_md5_etag(&cache_file_path) {
Some(file_etag) => {
let url_etag = get_digital_ocean_space_url_etag(url.clone()).await.unwrap();
if Some(&file_etag) == url_etag.as_ref() {
true
} else {
println!(
"etag mismatch, file: {filename}, local: {file_etag}, remote: {}",
url_etag.unwrap_or_default()
);
false
let mut tasks = FuturesUnordered::from_iter(urls.iter().map(|(filename, url)| {
let cached_file_path = cache_dir.join(filename);
async move {
let is_file_cached = match get_file_md5_etag(&cached_file_path) {
Some(file_etag) => {
let url_etag = get_digital_ocean_space_url_etag(url.clone()).await.unwrap();
if Some(&file_etag) == url_etag.as_ref() {
true
} else {
println!(
"etag mismatch, file: {filename}, local: {file_etag}, remote: {}",
url_etag.unwrap_or_default()
);
false
}
}
None => false,
};
if !is_file_cached {
println!("Downloading from {url} to {}", cached_file_path.display());
download_to(url, &cached_file_path).await.unwrap();
}
None => false,
};
if !is_file_cached {
println!("Downloading from {url} to {}", cache_file_path.display());
download_to(&url, &cache_file_path).await.unwrap();
(filename, cached_file_path)
}
}));

while let Some((filename, cached_file_path)) = tasks.next().await {
print!("Testing {filename} ...");
run_test_from_snapshot(&cache_file_path).await.unwrap();
run_test_from_snapshot(&cached_file_path).await.unwrap();
println!(" succeeded.");
}
}
Expand Down

0 comments on commit 3bae32a

Please sign in to comment.