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

test: regression test all files #325

Merged
merged 2 commits into from
Jul 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 30 additions & 8 deletions crates/committer_cli/src/tests/regression_tests.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
use std::collections::HashMap;
use std::{collections::HashMap, fs};

use committer::{
block_committer::input::{ConfigImpl, Input},
Expand All @@ -22,6 +22,7 @@ const MAX_TIME_FOR_COMMITTER_FLOW_BECHMARK_TEST: f64 = 5.0;
const SINGLE_TREE_FLOW_INPUT: &str = include_str!("../../benches/tree_flow_inputs.json");
const FLOW_TEST_INPUT: &str = include_str!("../../benches/committer_flow_inputs.json");
const OUTPUT_PATH: &str = "benchmark_output.txt";
const EXPECTED_NUMBER_OF_FILES: usize = 100;

#[derive(derive_more::Deref)]
struct FactMap(Map<String, Value>);
Expand Down Expand Up @@ -100,7 +101,7 @@ impl<'de> Deserialize<'de> for TreeRegressionInput {
}
}

#[ignore = "To avoid running the benchmark test in Coverage or without the --release flag."]
#[ignore = "To avoid running the regression test in Coverage or without the --release flag."]
#[tokio::test(flavor = "multi_thread")]
pub async fn test_regression_single_tree() {
let TreeRegressionInput {
Expand Down Expand Up @@ -135,19 +136,17 @@ pub async fn test_regression_single_tree() {
assert!(execution_time.as_secs_f64() < MAX_TIME_FOR_SINGLE_TREE_BECHMARK_TEST);
}

#[ignore = "To avoid running the benchmark test in Coverage or without the --release flag."]
#[tokio::test(flavor = "multi_thread")]
pub async fn test_regression_committer_flow() {
pub async fn test_single_committer_flow(input: &str, output_path: &str) {
let CommitterRegressionInput {
committer_input,
contract_states_root: expected_contract_states_root,
contract_classes_root: expected_contract_classes_root,
expected_facts,
} = serde_json::from_str(FLOW_TEST_INPUT).unwrap();
} = serde_json::from_str(input).unwrap();

let start = std::time::Instant::now();
// Benchmark the committer flow test.
commit(committer_input.0, OUTPUT_PATH.to_owned()).await;
commit(committer_input.0, output_path.to_owned()).await;
let execution_time = std::time::Instant::now() - start;

// Assert correctness of the output of the committer flow test.
Expand All @@ -157,7 +156,7 @@ pub async fn test_regression_committer_flow() {
storage: StorageObject {
storage: Value::Object(storage_changes),
},
} = serde_json::from_str(&std::fs::read_to_string(OUTPUT_PATH).unwrap()).unwrap()
} = serde_json::from_str(&std::fs::read_to_string(output_path).unwrap()).unwrap()
else {
panic!("Expected the storage to be an object.");
};
Expand All @@ -169,3 +168,26 @@ pub async fn test_regression_committer_flow() {
// Assert the execution time does not exceed the threshold.
assert!(execution_time.as_secs_f64() < MAX_TIME_FOR_COMMITTER_FLOW_BECHMARK_TEST);
}
#[ignore = "To avoid running the regression test in Coverage or without the --release flag."]
#[tokio::test(flavor = "multi_thread")]
pub async fn test_regression_committer_flow() {
test_single_committer_flow(FLOW_TEST_INPUT, OUTPUT_PATH).await;
}

#[ignore = "To avoid running the regression test in Coverage or without the --release flag."]
#[tokio::test(flavor = "multi_thread")]
pub async fn test_regression_committer_all_files() {
assert_eq!(
fs::read_dir("./benches/regression_files").unwrap().count(),
EXPECTED_NUMBER_OF_FILES
);
let dir_path = fs::read_dir("./benches/regression_files").unwrap();
for file_path in dir_path {
// TODO(Aner, 23/07/24): multi-thread the test.
test_single_committer_flow(
&fs::read_to_string(file_path.unwrap().path()).unwrap(),
OUTPUT_PATH,
)
.await;
}
}
Loading