-
Notifications
You must be signed in to change notification settings - Fork 1.6k
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
feat(fuzz) - add test progress #7914
Merged
Merged
Changes from 7 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
a3e7d97
feat(forge) - add test progress
grandizzy d479bd0
Code cleanup
grandizzy c6f92fd
Invariant progress bar cleanup
grandizzy 0672dff
Display number of threads and shrink run counter
grandizzy 0a338f2
Add progress for regular fuzz tests too
grandizzy fd21f0b
Cleanup code, use rayon collect
grandizzy ddbeabd
Merge remote-tracking branch 'origin' into test-progress
grandizzy 38e5343
Merge remote-tracking branch 'origin' into test-progress
grandizzy efe5a22
Merge remote-tracking branch 'origin' into test-progress
grandizzy 6233ae6
Merge remote-tracking branch 'origin' into test-progress
grandizzy 7aaafc8
Changes after review. Cleanup
grandizzy 77e85ff
Merge branch 'master' into test-progress
grandizzy 42cae1f
Fix clippy
grandizzy fedd8f6
Merge branch 'master' into test-progress
grandizzy File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
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 |
---|---|---|
|
@@ -43,3 +43,4 @@ parking_lot = "0.12" | |
proptest = "1" | ||
thiserror = "1" | ||
tracing = "0.1" | ||
indicatif = "0.17" |
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
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
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
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
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
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 |
---|---|---|
|
@@ -4,6 +4,7 @@ use crate::{result::SuiteResult, ContractRunner, TestFilter, TestOptions}; | |
use alloy_json_abi::{Function, JsonAbi}; | ||
use alloy_primitives::{Address, Bytes, U256}; | ||
use eyre::Result; | ||
use foundry_cli::{init_test_suite_progress, init_tests_progress}; | ||
use foundry_common::{get_contract_name, ContractsByArtifact, TestFunctionExt}; | ||
use foundry_compilers::{artifacts::Libraries, Artifact, ArtifactId, ProjectCompileOutput}; | ||
use foundry_config::Config; | ||
|
@@ -12,6 +13,7 @@ use foundry_evm::{ | |
inspectors::CheatsConfig, opts::EvmOpts, revm, | ||
}; | ||
use foundry_linking::{LinkOutput, Linker}; | ||
use indicatif::{MultiProgress, ProgressBar}; | ||
use rayon::prelude::*; | ||
use revm::primitives::SpecId; | ||
use std::{ | ||
|
@@ -20,7 +22,7 @@ use std::{ | |
fmt::Debug, | ||
path::Path, | ||
sync::{mpsc, Arc}, | ||
time::Instant, | ||
time::{Duration, Instant}, | ||
}; | ||
|
||
#[derive(Debug, Clone)] | ||
|
@@ -136,7 +138,7 @@ impl MultiContractRunner { | |
filter: &dyn TestFilter, | ||
) -> impl Iterator<Item = (String, SuiteResult)> { | ||
let (tx, rx) = mpsc::channel(); | ||
self.test(filter, tx); | ||
self.test(filter, tx, false); | ||
rx.into_iter() | ||
} | ||
|
||
|
@@ -146,7 +148,12 @@ impl MultiContractRunner { | |
/// before executing all contracts and their tests in _parallel_. | ||
/// | ||
/// Each Executor gets its own instance of the `Backend`. | ||
pub fn test(&mut self, filter: &dyn TestFilter, tx: mpsc::Sender<(String, SuiteResult)>) { | ||
pub fn test( | ||
&mut self, | ||
filter: &dyn TestFilter, | ||
tx: mpsc::Sender<(String, SuiteResult)>, | ||
show_progress: bool, | ||
) { | ||
let handle = tokio::runtime::Handle::current(); | ||
trace!("running all tests"); | ||
|
||
|
@@ -163,11 +170,54 @@ impl MultiContractRunner { | |
find_time, | ||
); | ||
|
||
contracts.par_iter().for_each_with(tx, |tx, &(id, contract)| { | ||
let _guard = handle.enter(); | ||
let result = self.run_tests(id, contract, db.clone(), filter, &handle); | ||
let _ = tx.send((id.identifier(), result)); | ||
}) | ||
if show_progress { | ||
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. ok with this for now, but I think we want to have one single par_iter here and also handle all output in between progress bars |
||
// Create overall tests progress and progress bar. | ||
// Tests progress is passed to test runners for adding individual test suite progress. | ||
// Progress bar is updated each time a test suite ends. | ||
let (tests_progress, progress_bar) = | ||
init_tests_progress!(contracts.len(), rayon::current_num_threads()); | ||
// Collect test suite results to stream at the end of test run. | ||
let results: Vec<(String, SuiteResult)> = contracts | ||
.par_iter() | ||
.map(|&(id, contract)| { | ||
let _guard = handle.enter(); | ||
// Add test suite progress to tests result. | ||
let suite_progress = init_test_suite_progress!(tests_progress, id.name); | ||
|
||
// Run tests, pass tests progress and current test suite progress in order | ||
// to add specific run details. | ||
let result = self.run_tests( | ||
id, | ||
contract, | ||
db.clone(), | ||
filter, | ||
&handle, | ||
Some((&tests_progress, &suite_progress)), | ||
); | ||
|
||
// Print result summary and remove test progress from overall progress. | ||
tests_progress.suspend(|| { | ||
println!("{}\n ↪ {}", id.name.clone(), result.summary()); | ||
}); | ||
suite_progress.finish_and_clear(); | ||
// Increment test progress bar to reflect completed test suite. | ||
progress_bar.inc(1); | ||
|
||
(id.identifier(), result) | ||
}) | ||
.collect(); | ||
// Tests completed, remove progress and stream results. | ||
tests_progress.clear().unwrap(); | ||
results.iter().for_each(|result| { | ||
let _ = tx.send(result.to_owned()); | ||
}); | ||
} else { | ||
contracts.par_iter().for_each_with(tx, |tx, &(id, contract)| { | ||
let _guard = handle.enter(); | ||
let result = self.run_tests(id, contract, db.clone(), filter, &handle, None); | ||
let _ = tx.send((id.identifier(), result)); | ||
}) | ||
} | ||
} | ||
|
||
fn run_tests( | ||
|
@@ -177,6 +227,7 @@ impl MultiContractRunner { | |
db: Backend, | ||
filter: &dyn TestFilter, | ||
handle: &tokio::runtime::Handle, | ||
progress: Option<(&MultiProgress, &ProgressBar)>, | ||
) -> SuiteResult { | ||
let identifier = artifact_id.identifier(); | ||
let mut span_name = identifier.as_str(); | ||
|
@@ -223,7 +274,7 @@ impl MultiContractRunner { | |
&self.revert_decoder, | ||
self.debug, | ||
); | ||
let r = runner.run_tests(filter, &self.test_options, known_contracts, handle); | ||
let r = runner.run_tests(filter, &self.test_options, known_contracts, handle, progress); | ||
|
||
debug!(duration=?r.duration, "executed all tests in contract"); | ||
|
||
|
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I know this is how it exists already, but I'd like these macros to be helper functions and/or structs instead, since that's all they are
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I removed those macros and moved logic in structs within newly
progress
mod, pls check 7aaafc8