From e311aacdff0eb192055a6f5abd00840b722e829c Mon Sep 17 00:00:00 2001 From: lemmih Date: Fri, 3 Nov 2023 09:58:48 +0100 Subject: [PATCH 1/3] add filtering and early exit to api compare command --- src/tool/subcommands/api_cmd.rs | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/src/tool/subcommands/api_cmd.rs b/src/tool/subcommands/api_cmd.rs index 2dfc1733af69..41e415a2b809 100644 --- a/src/tool/subcommands/api_cmd.rs +++ b/src/tool/subcommands/api_cmd.rs @@ -28,6 +28,12 @@ pub enum ApiCommands { /// Snapshot input paths. Supports `.car`, `.car.zst`, and `.forest.car.zst`. #[arg()] snapshot_files: Vec, + /// Test filter + #[arg(long, default_value = "")] + filter: String, + /// Cancel test run on the first failure + #[arg(long)] + fail_fast: bool, }, } @@ -38,13 +44,15 @@ impl ApiCommands { forest, lotus, snapshot_files, - } => compare_apis(forest, lotus, snapshot_files).await?, + filter, + fail_fast, + } => compare_apis(forest, lotus, snapshot_files, filter, fail_fast).await?, } Ok(()) } } -#[derive(Debug, Clone, PartialOrd, Ord, PartialEq, Eq, Hash)] +#[derive(Debug, Clone, Copy, PartialOrd, Ord, PartialEq, Eq, Hash)] enum EndpointStatus { // RPC method is missing MissingMethod, @@ -293,6 +301,8 @@ async fn compare_apis( forest: ApiInfo, lotus: ApiInfo, snapshot_files: Vec, + filter: String, + fail_fast: bool, ) -> anyhow::Result<()> { let mut tests = vec![]; @@ -308,14 +318,24 @@ async fn compare_apis( tests.extend(snapshot_tests(&store)?); } + tests.sort_by_key(|test| test.request.method_name); + let mut results = HashMap::default(); for test in tests.into_iter() { + if !test.request.method_name.contains(&filter) { + continue; + } let (forest_status, lotus_status) = test.run(&forest, &lotus).await; results .entry((test.request.method_name, forest_status, lotus_status)) .and_modify(|v| *v += 1) .or_insert(1u32); + if (forest_status != EndpointStatus::Valid || lotus_status != EndpointStatus::Valid) + && fail_fast + { + break; + } } let mut results = results.into_iter().collect::>(); From b3134cdb5b77c1cb1b488e9972d414705757744e Mon Sep 17 00:00:00 2001 From: lemmih Date: Fri, 3 Nov 2023 14:30:12 +0100 Subject: [PATCH 2/3] add changelog entry --- CHANGELOG.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index e7454c7a747e..92f45671f955 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -29,6 +29,9 @@ ### Added +- [#3662](https://github.com/ChainSafe/forest/pull/3662) Add `--filter` and + `--fail-fast` flags to `forest-tool api compare`. + ### Changed ### Removed From fe40d2ed8ad0c19fe8a81e89e7052803f593776f Mon Sep 17 00:00:00 2001 From: lemmih Date: Mon, 6 Nov 2023 07:59:26 +0100 Subject: [PATCH 3/3] elaborate on test filtering --- src/tool/subcommands/api_cmd.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tool/subcommands/api_cmd.rs b/src/tool/subcommands/api_cmd.rs index 41e415a2b809..9c4534a6c832 100644 --- a/src/tool/subcommands/api_cmd.rs +++ b/src/tool/subcommands/api_cmd.rs @@ -28,7 +28,7 @@ pub enum ApiCommands { /// Snapshot input paths. Supports `.car`, `.car.zst`, and `.forest.car.zst`. #[arg()] snapshot_files: Vec, - /// Test filter + /// Filter which tests to run according to method name. Case sensitive. #[arg(long, default_value = "")] filter: String, /// Cancel test run on the first failure