|
| 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