diff --git a/Cargo.lock b/Cargo.lock index ce592e16..02eaf03f 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -1028,7 +1028,7 @@ dependencies = [ [[package]] name = "ndc-client" version = "0.1.0" -source = "git+http://github.com/hasura/ndc-spec.git?rev=cf9f8d2350618b595b7d030eaa1cf0d5312726a1#cf9f8d2350618b595b7d030eaa1cf0d5312726a1" +source = "git+http://github.com/hasura/ndc-spec.git?tag=v0.1.0-rc.19#0c7f807d331ad8324d8edcf6f7c4c9958e47e3b1" dependencies = [ "async-trait", "indexmap 2.1.0", @@ -1081,7 +1081,7 @@ dependencies = [ [[package]] name = "ndc-test" version = "0.1.0" -source = "git+http://github.com/hasura/ndc-spec.git?rev=cf9f8d2350618b595b7d030eaa1cf0d5312726a1#cf9f8d2350618b595b7d030eaa1cf0d5312726a1" +source = "git+http://github.com/hasura/ndc-spec.git?tag=v0.1.0-rc.19#0c7f807d331ad8324d8edcf6f7c4c9958e47e3b1" dependencies = [ "async-trait", "clap", diff --git a/rust-connector-sdk/Cargo.toml b/rust-connector-sdk/Cargo.toml index 759e3e59..3eb706e4 100644 --- a/rust-connector-sdk/Cargo.toml +++ b/rust-connector-sdk/Cargo.toml @@ -13,8 +13,8 @@ path = "bin/main.rs" [dependencies] gdc_rust_types = { git = "https://github.com/hasura/gdc_rust_types.git", rev = "3273434" } -ndc-client = { git = "http://github.com/hasura/ndc-spec.git", rev = "cf9f8d2350618b595b7d030eaa1cf0d5312726a1" } -ndc-test = { git = "http://github.com/hasura/ndc-spec.git", rev = "cf9f8d2350618b595b7d030eaa1cf0d5312726a1" } +ndc-client = { git = "http://github.com/hasura/ndc-spec.git", tag = "v0.1.0-rc.19" } +ndc-test = { git = "http://github.com/hasura/ndc-spec.git", tag = "v0.1.0-rc.19" } async-trait = "^0.1.74" axum = "^0.6.20" diff --git a/rust-connector-sdk/src/default_main.rs b/rust-connector-sdk/src/default_main.rs index e21f3726..b03a5414 100644 --- a/rust-connector-sdk/src/default_main.rs +++ b/rust-connector-sdk/src/default_main.rs @@ -47,6 +47,8 @@ enum Command { #[command()] Replay(ReplayCommand), #[command()] + Bench(BenchCommand), + #[command()] CheckHealth(CheckHealthCommand), } @@ -89,6 +91,27 @@ struct ReplayCommand { snapshots_dir: PathBuf, } +#[derive(Clone, Parser)] +struct BenchCommand { + #[arg(long, value_name = "DIRECTORY", env = "HASURA_CONFIGURATION_DIRECTORY")] + configuration: PathBuf, + #[arg( + long, + value_name = "COUNT", + help = "the number of samples to collect per test", + default_value = "100" + )] + samples: u32, + #[arg( + long, + value_name = "TOLERANCE", + help = "tolerable deviation from previous report, in standard deviations from the mean" + )] + tolerance: Option, + #[arg(long, value_name = "DIRECTORY", env = "HASURA_SNAPSHOTS_DIR")] + snapshots_dir: PathBuf, +} + #[derive(Clone, Parser)] struct CheckHealthCommand { #[arg(long, value_name = "HOST")] @@ -183,6 +206,7 @@ where match command { Command::Serve(serve_command) => serve(setup, serve_command).await, Command::Test(test_command) => test(setup, test_command).await, + Command::Bench(bench_command) => bench(setup, bench_command).await, Command::Replay(replay_command) => replay(setup, replay_command).await, Command::CheckHealth(check_health_command) => check_health(check_health_command).await, } @@ -572,6 +596,36 @@ async fn replay( Ok(()) } +async fn bench( + setup: Setup, + command: BenchCommand, +) -> Result<(), Box> { + let configuration = ndc_test::ReportConfiguration { + samples: command.samples, + tolerance: command.tolerance, + }; + + let connector = make_connector_adapter(setup, command.configuration).await?; + let mut reporter = (ConsoleReporter::new(), TestResults::default()); + + ndc_test::bench_snapshots_in_directory( + &configuration, + &connector, + &mut reporter, + command.snapshots_dir, + ) + .await + .map_err(|e| e.to_string())?; + + if !reporter.1.failures.is_empty() { + println!(); + println!("{}", reporter.1.report()); + + exit(1) + } + + Ok(()) +} async fn make_connector_adapter( setup: Setup,