-
Notifications
You must be signed in to change notification settings - Fork 189
test: refactor rpc_regression_tests into individual tests
#5930
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
1ff3b06
9465a3d
f3e4098
70c514f
4226287
d79829a
f77040a
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -184,68 +184,55 @@ mod tests { | |
| use crate::utils::net::{DownloadFileOption, download_file_with_cache}; | ||
| use crate::utils::proofs_api::ensure_proof_params_downloaded; | ||
| use ahash::HashSet; | ||
| use anyhow::Context as _; | ||
| use directories::ProjectDirs; | ||
| use futures::{StreamExt, stream::FuturesUnordered}; | ||
| use itertools::Itertools as _; | ||
| use std::sync::LazyLock; | ||
| use std::time::Instant; | ||
| use tokio::sync::Semaphore; | ||
| use tokio::sync::Mutex; | ||
| use url::Url; | ||
|
|
||
| #[tokio::test(flavor = "multi_thread")] | ||
| async fn rpc_regression_tests() { | ||
| // To run a single test: cargo test --lib filecoin_multisig_statedecodeparams_1754230255631789 -- --nocapture | ||
| include!(concat!(env!("OUT_DIR"), "/__rpc_regression_tests_gen.rs")); | ||
|
|
||
| async fn rpc_regression_test_run(name: &str) { | ||
| // Skip for debug build on CI as the downloading is slow and flaky | ||
| if crate::utils::is_ci() && crate::utils::is_debug_build() { | ||
| return; | ||
| } | ||
|
|
||
| // Set proof parameter data dir and make sure the proofs are available | ||
| crate::utils::proofs_api::maybe_set_proofs_parameter_cache_dir_env( | ||
| &Config::default().client.data_dir, | ||
| ); | ||
| ensure_proof_params_downloaded().await.unwrap(); | ||
| let urls = include_str!("test_snapshots.txt") | ||
| .trim() | ||
| .split("\n") | ||
| .filter_map(|n| { | ||
| Url::parse( | ||
| format!( | ||
| "https://forest-snapshots.fra1.cdn.digitaloceanspaces.com/rpc_test/{n}" | ||
| ) | ||
| .as_str(), | ||
| ) | ||
| .ok() | ||
| .map(|url| (n, url)) | ||
| }) | ||
| .collect_vec(); | ||
| { | ||
| static PROOF_PARAMS_LOCK: LazyLock<Mutex<()>> = LazyLock::new(|| Mutex::new(())); | ||
| let _guard = PROOF_PARAMS_LOCK.lock().await; | ||
| crate::utils::proofs_api::maybe_set_proofs_parameter_cache_dir_env( | ||
| &Config::default().client.data_dir, | ||
| ); | ||
| ensure_proof_params_downloaded().await.unwrap(); | ||
| } | ||
| let url: Url = | ||
| format!("https://forest-snapshots.fra1.cdn.digitaloceanspaces.com/rpc_test/{name}") | ||
| .parse() | ||
| .with_context(|| format!("Failed to parse URL for test: {name}")) | ||
| .unwrap(); | ||
| let project_dir = ProjectDirs::from("com", "ChainSafe", "Forest").unwrap(); | ||
| let cache_dir = project_dir.cache_dir().join("test").join("rpc-snapshots"); | ||
| let semaphore = Arc::new(Semaphore::new(4)); | ||
| let mut tasks = FuturesUnordered::from_iter(urls.into_iter().map(|(filename, url)| { | ||
| let cache_dir = cache_dir.clone(); | ||
| let semaphore = semaphore.clone(); | ||
| async move { | ||
| let _permit = semaphore.acquire().await.unwrap(); | ||
| let result = | ||
| download_file_with_cache(&url, &cache_dir, DownloadFileOption::NonResumable) | ||
| .await | ||
| .unwrap(); | ||
| (filename, result.path) | ||
| } | ||
| })); | ||
| let path = download_file_with_cache(&url, &cache_dir, DownloadFileOption::NonResumable) | ||
| .await | ||
| .unwrap() | ||
| .path; | ||
|
|
||
| // We need to set RNG seed so that tests are run with deterministic | ||
| // output. The snapshots should be generated with a node running with the same seed, if | ||
| // they are testing methods that are not deterministic, e.g., | ||
| // `[`crate::rpc::methods::gas::estimate_gas_premium`]`. | ||
| unsafe { std::env::set_var(crate::utils::rand::FIXED_RNG_SEED_ENV, "4213666") }; | ||
| while let Some((filename, file_path)) = tasks.next().await { | ||
| print!("Testing {filename} ..."); | ||
| let start = Instant::now(); | ||
| run_test_from_snapshot(&file_path).await.unwrap(); | ||
| println!( | ||
| " succeeded, took {}.", | ||
| humantime::format_duration(start.elapsed()) | ||
| ); | ||
| } | ||
| print!("Testing {name} ..."); | ||
| let start = Instant::now(); | ||
| run_test_from_snapshot(&path).await.unwrap(); | ||
| println!( | ||
| " succeeded, took {}.", | ||
| humantime::format_duration(start.elapsed()) | ||
| ); | ||
|
Comment on lines
+229
to
+235
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we need the manual timings? Isn't it redundant by what
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. It's still helpful for |
||
| } | ||
|
|
||
| #[test] | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.