From 6236ba993dbeaeda57eee7bde11bfb5145d36f35 Mon Sep 17 00:00:00 2001 From: aner-starkware <147302140+aner-starkware@users.noreply.github.com> Date: Wed, 24 Jul 2024 14:15:56 +0300 Subject: [PATCH] test: regression test all files (#325) * test: regression test for all regression files * refactor: extract assert committer flow function --- .../src/tests/regression_tests.rs | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/crates/committer_cli/src/tests/regression_tests.rs b/crates/committer_cli/src/tests/regression_tests.rs index fa0b1baf49..f6f1d1b518 100644 --- a/crates/committer_cli/src/tests/regression_tests.rs +++ b/crates/committer_cli/src/tests/regression_tests.rs @@ -1,4 +1,4 @@ -use std::collections::HashMap; +use std::{collections::HashMap, fs}; use committer::{ block_committer::input::{ConfigImpl, Input}, @@ -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); @@ -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 { @@ -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. @@ -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."); }; @@ -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; + } +}