Skip to content

Commit

Permalink
Use tag, add bench command to SDK
Browse files Browse the repository at this point in the history
  • Loading branch information
paf31 committed Mar 1, 2024
1 parent 51ec642 commit 4d47b3e
Show file tree
Hide file tree
Showing 3 changed files with 58 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions rust-connector-sdk/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
54 changes: 54 additions & 0 deletions rust-connector-sdk/src/default_main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ enum Command {
#[command()]
Replay(ReplayCommand),
#[command()]
Bench(BenchCommand),
#[command()]
CheckHealth(CheckHealthCommand),
}

Expand Down Expand Up @@ -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<f64>,
#[arg(long, value_name = "DIRECTORY", env = "HASURA_SNAPSHOTS_DIR")]
snapshots_dir: PathBuf,
}

#[derive(Clone, Parser)]
struct CheckHealthCommand {
#[arg(long, value_name = "HOST")]
Expand Down Expand Up @@ -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,
}
Expand Down Expand Up @@ -572,6 +596,36 @@ async fn replay<Setup: ConnectorSetup>(

Ok(())
}
async fn bench<Setup: ConnectorSetup>(
setup: Setup,
command: BenchCommand,
) -> Result<(), Box<dyn Error + Send + Sync>> {
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: ConnectorSetup>(
setup: Setup,
Expand Down

0 comments on commit 4d47b3e

Please sign in to comment.