Skip to content

Commit 914924d

Browse files
authored
[nexus] Refactor test-utilities to helper crate, add test benchmarks (#492)
1 parent a628762 commit 914924d

27 files changed

+325
-89
lines changed

Cargo.lock

+173-2
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+2
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ members = [
33
"common",
44
"nexus",
55
"nexus/src/db/db-macros",
6+
"nexus/test-utils",
67
"nexus-client",
78
"package",
89
"rpaths",
@@ -22,6 +23,7 @@ default-members = [
2223
"common",
2324
"nexus",
2425
"nexus/src/db/db-macros",
26+
"nexus/test-utils",
2527
"package",
2628
"rpaths",
2729
"sled-agent",

nexus/Cargo.toml

+5-4
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,9 @@ version = "0.8"
107107
features = [ "serde", "v4" ]
108108

109109
[dev-dependencies]
110-
bytes = "1.0.1"
110+
criterion = { version = "0.3", features = [ "async_tokio" ] }
111111
expectorate = "1.0.4"
112+
nexus-test-utils = { path = "test-utils" }
112113
omicron-test-utils = { path = "../test-utils" }
113114
openapiv3 = "0.5.0"
114115
oximeter-db = { path = "../oximeter/db" }
@@ -118,9 +119,9 @@ subprocess = "0.2.8"
118119
git = "https://github.com/oxidecomputer/openapi-lint"
119120
branch = "main"
120121

121-
[dev-dependencies.oximeter-collector]
122-
version = "0.1.0"
123-
path = "../oximeter/collector"
122+
[[bench]]
123+
name = "setup_benchmark"
124+
harness = false
124125

125126
#
126127
# Disable doc builds by default for our binaries to work around issue

nexus/benches/setup_benchmark.rs

+59
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
// This Source Code Form is subject to the terms of the Mozilla Public
2+
// License, v. 2.0. If a copy of the MPL was not distributed with this
3+
// file, You can obtain one at https://mozilla.org/MPL/2.0/.
4+
5+
//! Benchmarks test setup/teardown.
6+
7+
use criterion::{criterion_group, criterion_main, Criterion};
8+
use dropshot::test_util::LogContext;
9+
use omicron_test_utils::dev;
10+
11+
// This is the default wrapper around most Nexus integration tests.
12+
// Benchmark how long an "empty test" would take.
13+
async fn do_full_setup() {
14+
let ctx = nexus_test_utils::test_setup("full_setup").await;
15+
ctx.teardown().await;
16+
}
17+
18+
// Wraps exclusively the CockroachDB portion of setup/teardown.
19+
async fn do_crdb_setup() {
20+
let cfg = nexus_test_utils::load_test_config();
21+
let logctx = LogContext::new("crdb_setup", &cfg.log);
22+
let mut db = dev::test_setup_database(&logctx.log).await;
23+
db.cleanup().await.unwrap();
24+
}
25+
26+
// Wraps exclusively the ClickhouseDB portion of setup/teardown.
27+
async fn do_clickhouse_setup() {
28+
let mut clickhouse =
29+
dev::clickhouse::ClickHouseInstance::new(0).await.unwrap();
30+
clickhouse.cleanup().await.unwrap();
31+
}
32+
33+
fn setup_benchmark(c: &mut Criterion) {
34+
let mut group = c.benchmark_group("Test Setup");
35+
group.bench_function("do_full_setup", |b| {
36+
b.to_async(tokio::runtime::Runtime::new().unwrap())
37+
.iter(|| do_full_setup());
38+
});
39+
group.bench_function("do_crdb_setup", |b| {
40+
b.to_async(tokio::runtime::Runtime::new().unwrap())
41+
.iter(|| do_crdb_setup());
42+
});
43+
group.bench_function("do_clickhouse_setup", |b| {
44+
b.to_async(tokio::runtime::Runtime::new().unwrap())
45+
.iter(|| do_clickhouse_setup());
46+
});
47+
group.finish();
48+
}
49+
50+
criterion_group!(
51+
name = benches;
52+
// To accomodate the fact that these benchmarks are a bit bulky,
53+
// we set the following:
54+
// - Smaller sample size, to keep running time down
55+
// - Higher noise threshold, to avoid avoid false positive change detection
56+
config = Criterion::default().sample_size(10).noise_threshold(0.10);
57+
targets = setup_benchmark
58+
);
59+
criterion_main!(benches);

0 commit comments

Comments
 (0)