Skip to content
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

perf/refactor: partial test runner refactor #7109

Merged
merged 8 commits into from
Feb 14, 2024

Conversation

DaniPopes
Copy link
Member

@DaniPopes DaniPopes commented Feb 13, 2024

Numerous perf improvements and simplifications in test runner code.

  • make some more deps opt-level=3 in debug mode for testing, fuzzing performance
  • bump MSRV to 1.75 for Option::as_slice
  • Vec<TestOutcome> does not make sense, as only one TestOutcome is returned from the main testing function and it's the aggregate of all test suites. This fixes some displaying bugs
  • Moved types and some free functions from binary to library result.rs
  • Renamed Test to SuiteTestResult, kinda ran out of names, but it's better than just "test". This is constructed by flattening both maps in TestOutcome, and wraps a TestResult.
  • ...

Review with "hide whitespace"

@DaniPopes DaniPopes changed the title Dani/test runner refactor perf/refactor: partial test runner refactor Feb 13, 2024
Copy link
Member

@onbjerg onbjerg left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm, most of the debt here is from small refactoring in related parts of the code and not refactoring the entire thing (e.g. Vec<TestOutcome>)

makes sense to move free fns to lib

}

decoders.push(decoder);
}
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Decoder is now obtained from the initial test results.

let mut total_failed = 0;
let mut total_skipped = 0;
let mut suite_results: Vec<TestOutcome> = Vec::new();
// Build the trace decoder.
Copy link
Member Author

@DaniPopes DaniPopes Feb 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Multiple decoders don't achieve anything more than a single one, so reuse a single decoder and clear the test-dependent data to reuse allocations.

@@ -434,59 +383,60 @@ impl TestArgs {
TraceKind::Deployment => false,
};

// Traces need to be identified for gas reports too.
if should_include || self.gas_report {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Supersedes #7093

}

if self.gas_report {
gas_report.analyze(&result.traces, &decoder).await;
}

// If the test failed, we want to stop processing the rest of the tests
if self.fail_fast && result.status == TestStatus::Failure {
break 'outer
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This previously exited the loop without printing the summary. We also need to do this now since we push the results into the outcome at the end to avoid unnecessary cloning.

let block_outcome = TestOutcome::new(
[(contract_name.clone(), suite_result)].into(),
self.allow_failure,
);
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was pretty dumb.


total_passed += block_outcome.successes().count();
total_failed += block_outcome.failures().count();
total_skipped += block_outcome.skips().count();
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to lazily calculating later. It's cheap anyway.

@@ -550,157 +498,6 @@ impl Provider for TestArgs {
}
}

/// The result of a single test
#[derive(Clone, Debug)]
pub struct Test {
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Moved to library

@DaniPopes DaniPopes force-pushed the dani/test-runner-refactor branch 3 times, most recently from 32b0aa8 to 962eb31 Compare February 14, 2024 02:18
Copy link
Member

@mattsse mattsse left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

so glad we're making some progress on the runner stuff

Comment on lines +186 to +190
pub calls: Vec<u64>,
pub min: u64,
pub mean: u64,
pub median: u64,
pub max: u64,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this is much better

}

/// Flattens the test outcome into a list of individual tests.
// TODO: Replace this with `tests` and make it return `TestRef<'_>`
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good idea

@DaniPopes DaniPopes merged commit 85669c2 into master Feb 14, 2024
19 checks passed
@DaniPopes DaniPopes deleted the dani/test-runner-refactor branch February 14, 2024 22:29
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T-debt Type: code debt
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants