Skip to content

[nexus] Refactor test-utilities to helper crate, add test benchmarks #492

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

Merged
merged 8 commits into from
Dec 9, 2021
Merged
Show file tree
Hide file tree
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
175 changes: 173 additions & 2 deletions Cargo.lock

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

2 changes: 2 additions & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ members = [
"common",
"nexus",
"nexus/src/db/db-macros",
"nexus/test-utils",
"nexus-client",
"package",
"rpaths",
Expand All @@ -22,6 +23,7 @@ default-members = [
"common",
"nexus",
"nexus/src/db/db-macros",
"nexus/test-utils",
"package",
"rpaths",
"sled-agent",
Expand Down
9 changes: 5 additions & 4 deletions nexus/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -107,8 +107,9 @@ version = "0.8"
features = [ "serde", "v4" ]

[dev-dependencies]
bytes = "1.0.1"
criterion = { version = "0.3", features = [ "async_tokio" ] }
expectorate = "1.0.4"
nexus-test-utils = { path = "test-utils" }
omicron-test-utils = { path = "../test-utils" }
openapiv3 = "0.5.0"
oximeter-db = { path = "../oximeter/db" }
Expand All @@ -118,9 +119,9 @@ subprocess = "0.2.8"
git = "https://github.com/oxidecomputer/openapi-lint"
branch = "main"

[dev-dependencies.oximeter-collector]
version = "0.1.0"
path = "../oximeter/collector"
[[bench]]
name = "setup_benchmark"
harness = false

#
# Disable doc builds by default for our binaries to work around issue
Expand Down
59 changes: 59 additions & 0 deletions nexus/benches/setup_benchmark.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
// This Source Code Form is subject to the terms of the Mozilla Public
// License, v. 2.0. If a copy of the MPL was not distributed with this
// file, You can obtain one at https://mozilla.org/MPL/2.0/.

//! Benchmarks test setup/teardown.

use criterion::{criterion_group, criterion_main, Criterion};
use dropshot::test_util::LogContext;
use omicron_test_utils::dev;

// This is the default wrapper around most Nexus integration tests.
// Benchmark how long an "empty test" would take.
async fn do_full_setup() {
let ctx = nexus_test_utils::test_setup("full_setup").await;
ctx.teardown().await;
}

// Wraps exclusively the CockroachDB portion of setup/teardown.
async fn do_crdb_setup() {
let cfg = nexus_test_utils::load_test_config();
let logctx = LogContext::new("crdb_setup", &cfg.log);
let mut db = dev::test_setup_database(&logctx.log).await;
db.cleanup().await.unwrap();
}

// Wraps exclusively the ClickhouseDB portion of setup/teardown.
async fn do_clickhouse_setup() {
let mut clickhouse =
dev::clickhouse::ClickHouseInstance::new(0).await.unwrap();
clickhouse.cleanup().await.unwrap();
}

fn setup_benchmark(c: &mut Criterion) {
let mut group = c.benchmark_group("Test Setup");
group.bench_function("do_full_setup", |b| {
b.to_async(tokio::runtime::Runtime::new().unwrap())
.iter(|| do_full_setup());
});
group.bench_function("do_crdb_setup", |b| {
b.to_async(tokio::runtime::Runtime::new().unwrap())
.iter(|| do_crdb_setup());
});
group.bench_function("do_clickhouse_setup", |b| {
b.to_async(tokio::runtime::Runtime::new().unwrap())
.iter(|| do_clickhouse_setup());
});
group.finish();
}

criterion_group!(
name = benches;
// To accomodate the fact that these benchmarks are a bit bulky,
// we set the following:
// - Smaller sample size, to keep running time down
// - Higher noise threshold, to avoid avoid false positive change detection
config = Criterion::default().sample_size(10).noise_threshold(0.10);
targets = setup_benchmark
);
criterion_main!(benches);
Loading