From 082c009c197629cfe51de7a9ab1c6f5f2203a994 Mon Sep 17 00:00:00 2001 From: Sean Klein Date: Wed, 8 Dec 2021 14:01:24 -0500 Subject: [PATCH 1/3] [nexus] Refactor test-utilities to helper crate, add test benchmarks --- Cargo.lock | 233 +++++++++++++++--- nexus/Cargo.toml | 9 +- nexus/benches/setup_benchmark.rs | 59 +++++ nexus/test-utils/Cargo.toml | 26 ++ .../common => test-utils/src}/http_testing.rs | 0 .../common/mod.rs => test-utils/src/lib.rs} | 4 +- .../src}/resource_helpers.rs | 0 nexus/tests/test_authn_http.rs | 4 +- nexus/tests/test_authz.rs | 5 +- nexus/tests/test_basic.rs | 15 +- nexus/tests/test_console_api.rs | 5 +- nexus/tests/test_datasets.rs | 3 +- nexus/tests/test_disks.rs | 17 +- nexus/tests/test_instances.rs | 7 +- nexus/tests/test_organizations.rs | 9 +- nexus/tests/test_oximeter.rs | 24 +- nexus/tests/test_projects.rs | 5 +- nexus/tests/test_router_routes.rs | 5 +- nexus/tests/test_users_builtin.rs | 9 +- nexus/tests/test_vpc_firewall.rs | 5 +- nexus/tests/test_vpc_routers.rs | 7 +- nexus/tests/test_vpc_subnets.rs | 7 +- nexus/tests/test_vpcs.rs | 7 +- nexus/tests/test_zpools.rs | 3 +- 24 files changed, 354 insertions(+), 114 deletions(-) create mode 100644 nexus/benches/setup_benchmark.rs create mode 100644 nexus/test-utils/Cargo.toml rename nexus/{tests/common => test-utils/src}/http_testing.rs (100%) rename nexus/{tests/common/mod.rs => test-utils/src/lib.rs} (99%) rename nexus/{tests/common => test-utils/src}/resource_helpers.rs (100%) diff --git a/Cargo.lock b/Cargo.lock index 00c2e49d1df..29f3fe0f92e 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -267,6 +267,18 @@ dependencies = [ "byte-tools", ] +[[package]] +name = "bstr" +version = "0.2.17" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "ba3569f383e8f1598449f1a423e72e99569137b47740b1da11ef19af3d5c3223" +dependencies = [ + "lazy_static", + "memchr", + "regex-automata", + "serde", +] + [[package]] name = "bumpalo" version = "3.8.0" @@ -294,6 +306,15 @@ dependencies = [ "serde", ] +[[package]] +name = "cast" +version = "0.2.7" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "4c24dab4283a142afa2fdca129b80ad2c6284e073930f964c3a1293c225ee39a" +dependencies = [ + "rustc_version 0.4.0", +] + [[package]] name = "cc" version = "1.0.72" @@ -397,6 +418,44 @@ dependencies = [ "libc", ] +[[package]] +name = "criterion" +version = "0.3.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "1604dafd25fba2fe2d5895a9da139f8dc9b319a5fe5354ca137cbbce4e178d10" +dependencies = [ + "atty", + "cast", + "clap", + "criterion-plot", + "csv", + "futures", + "itertools", + "lazy_static", + "num-traits", + "oorandom", + "plotters", + "rayon", + "regex", + "serde", + "serde_cbor", + "serde_derive", + "serde_json", + "tinytemplate", + "tokio", + "walkdir", +] + +[[package]] +name = "criterion-plot" +version = "0.4.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d00996de9f2f7559f7f4dc286073197f83e92256a59ed395f9aac01fe717da57" +dependencies = [ + "cast", + "itertools", +] + [[package]] name = "crossbeam-channel" version = "0.5.1" @@ -444,7 +503,7 @@ dependencies = [ [[package]] name = "crucible" version = "0.0.1" -source = "git+https://github.com/oxidecomputer/crucible?branch=main#cda0bf8b0fd8e53566d1918b4d14824103a1d410" +source = "git+https://github.com/oxidecomputer/crucible?branch=main#4f02540ab2557ad75e9f170d362dc889eefe1d1b" dependencies = [ "aes", "aes-gcm-siv", @@ -474,7 +533,7 @@ dependencies = [ [[package]] name = "crucible-common" version = "0.0.0" -source = "git+https://github.com/oxidecomputer/crucible?branch=main#cda0bf8b0fd8e53566d1918b4d14824103a1d410" +source = "git+https://github.com/oxidecomputer/crucible?branch=main#4f02540ab2557ad75e9f170d362dc889eefe1d1b" dependencies = [ "anyhow", "serde", @@ -488,7 +547,7 @@ dependencies = [ [[package]] name = "crucible-protocol" version = "0.0.0" -source = "git+https://github.com/oxidecomputer/crucible?branch=main#cda0bf8b0fd8e53566d1918b4d14824103a1d410" +source = "git+https://github.com/oxidecomputer/crucible?branch=main#4f02540ab2557ad75e9f170d362dc889eefe1d1b" dependencies = [ "anyhow", "bincode", @@ -502,7 +561,7 @@ dependencies = [ [[package]] name = "crucible-scope" version = "0.0.0" -source = "git+https://github.com/oxidecomputer/crucible?branch=main#cda0bf8b0fd8e53566d1918b4d14824103a1d410" +source = "git+https://github.com/oxidecomputer/crucible?branch=main#4f02540ab2557ad75e9f170d362dc889eefe1d1b" dependencies = [ "anyhow", "futures", @@ -542,6 +601,28 @@ dependencies = [ "subtle", ] +[[package]] +name = "csv" +version = "1.1.6" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "22813a6dc45b335f9bade10bf7271dc477e81113e89eb251a0bc2a8a81c536e1" +dependencies = [ + "bstr", + "csv-core", + "itoa", + "ryu", + "serde", +] + +[[package]] +name = "csv-core" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "2b2466559f260f48ad25fe6317b3c8dac77b5bdb5763ac7d9d6103530663bc90" +dependencies = [ + "memchr", +] + [[package]] name = "ctr" version = "0.8.0" @@ -566,9 +647,9 @@ dependencies = [ [[package]] name = "darling" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "757c0ded2af11d8e739c4daea1ac623dd1624b06c844cf3f5a39f1bdbd99bb12" +checksum = "d0d720b8683f8dd83c65155f0530560cba68cd2bf395f6513a483caee57ff7f4" dependencies = [ "darling_core", "darling_macro", @@ -576,9 +657,9 @@ dependencies = [ [[package]] name = "darling_core" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2c34d8efb62d0c2d7f60ece80f75e5c63c1588ba68032740494b0b9a996466e3" +checksum = "7a340f241d2ceed1deb47ae36c4144b2707ec7dd0b649f894cb39bb595986324" dependencies = [ "fnv", "ident_case", @@ -590,9 +671,9 @@ dependencies = [ [[package]] name = "darling_macro" -version = "0.13.0" +version = "0.13.1" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "ade7bff147130fe5e6d39f089c6bd49ec0250f35d70b2eebf72afdfc919f15cc" +checksum = "72c41b3b7352feb3211a0d743dc5700a4e3b60f51bd2b368892d1e0f9a95f44b" dependencies = [ "darling_core", "quote", @@ -610,9 +691,9 @@ dependencies = [ [[package]] name = "der" -version = "0.4.4" +version = "0.4.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "28e98c534e9c8a0483aa01d6f6913bc063de254311bd267c9cf535e9b70e15b2" +checksum = "79b71cca7d95d7681a4b3b9cdf63c8dbc3730d0584c2c74e31416d64a90493f4" dependencies = [ "const-oid", ] @@ -741,7 +822,7 @@ checksum = "4bb454f0228b18c7f4c3b0ebbee346ed9c52e7443b0999cd543ff3571205701d" [[package]] name = "dropshot" version = "0.6.1-dev" -source = "git+https://github.com/oxidecomputer/dropshot?branch=main#ff33033ad3d7fcf32caa352d76fc243bd20db176" +source = "git+https://github.com/oxidecomputer/dropshot?branch=main#56f60da71be392de46dd576e9564ac1b5428dd5c" dependencies = [ "async-trait", "base64", @@ -776,7 +857,7 @@ dependencies = [ [[package]] name = "dropshot_endpoint" version = "0.6.1-dev" -source = "git+https://github.com/oxidecomputer/dropshot?branch=main#ff33033ad3d7fcf32caa352d76fc243bd20db176" +source = "git+https://github.com/oxidecomputer/dropshot?branch=main#56f60da71be392de46dd576e9564ac1b5428dd5c" dependencies = [ "proc-macro2", "quote", @@ -853,9 +934,9 @@ dependencies = [ [[package]] name = "encoding_rs" -version = "0.8.29" +version = "0.8.30" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a74ea89a0a1b98f6332de42c95baff457ada66d1cb4030f9ff151b2041a1c746" +checksum = "7896dc8abb250ffdda33912550faa54c88ec8b998dec0b2c55ab224921ce11df" dependencies = [ "cfg-if", ] @@ -1376,9 +1457,9 @@ dependencies = [ [[package]] name = "itertools" -version = "0.10.1" +version = "0.10.3" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "69ddb889f9d0d08a67338271fa9b62996bc788c7796a5c18cf057420aaed5eaf" +checksum = "a9a9d19fa1e79b6215ff29b9d6880b706147f16e9b1dbb1e4e5947b5b02bc5e3" dependencies = [ "either", ] @@ -1520,9 +1601,9 @@ checksum = "308cc39be01b73d0d18f82a0e7b2a3df85245f84af96fdddc5d202d27e47b86a" [[package]] name = "memoffset" -version = "0.6.4" +version = "0.6.5" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "59accc507f1338036a0477ef61afdae33cde60840f4dfe481319ce3ad116ddf9" +checksum = "5aa361d4faea93603064a027415f07bd8e1d5c88c9fbf68bf56a285428fd79ce" dependencies = [ "autocfg", ] @@ -1647,6 +1728,31 @@ dependencies = [ "uuid", ] +[[package]] +name = "nexus-test-utils" +version = "0.1.0" +dependencies = [ + "anyhow", + "bytes", + "chrono", + "dropshot", + "http", + "hyper", + "omicron-common", + "omicron-nexus", + "omicron-sled-agent", + "omicron-test-utils", + "oximeter", + "oximeter-client", + "oximeter-collector", + "oximeter-producer", + "parse-display", + "serde", + "serde_json", + "slog", + "uuid", +] + [[package]] name = "normalize-line-endings" version = "0.3.0" @@ -1757,9 +1863,9 @@ dependencies = [ "async-bb8-diesel", "async-trait", "bb8", - "bytes", "chrono", "cookie", + "criterion", "db-macros", "diesel", "dropshot", @@ -1774,6 +1880,7 @@ dependencies = [ "macaddr", "mime_guess", "newtype_derive", + "nexus-test-utils", "omicron-common", "omicron-rpaths", "omicron-sled-agent", @@ -1783,7 +1890,6 @@ dependencies = [ "oso", "oximeter", "oximeter-client", - "oximeter-collector", "oximeter-db", "oximeter-instruments", "oximeter-producer", @@ -1909,6 +2015,12 @@ version = "1.8.0" source = "registry+https://github.com/rust-lang/crates.io-index" checksum = "692fcb63b64b1758029e0a96ee63e049ce8c5948587f2f7208df04625e5f6b56" +[[package]] +name = "oorandom" +version = "11.1.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "0ab1bc2a289d34bd04a330323ac98a1b4bc82c9d9fcb1e66b63caa84da26b575" + [[package]] name = "opaque-debug" version = "0.2.3" @@ -2340,9 +2452,37 @@ dependencies = [ [[package]] name = "pkg-config" -version = "0.3.22" +version = "0.3.23" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "d1a3ea4f0dd7f1f3e512cf97bf100819aa547f36a6eccac8dbaae839eb92363e" + +[[package]] +name = "plotters" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "32a3fd9ec30b9749ce28cd91f255d569591cdf937fe280c312143e3c4bad6f2a" +dependencies = [ + "num-traits", + "plotters-backend", + "plotters-svg", + "wasm-bindgen", + "web-sys", +] + +[[package]] +name = "plotters-backend" +version = "0.3.2" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "12295df4f294471248581bc09bef3c38a5e46f1e36d6a37353621a0c6c357e1f" +checksum = "d88417318da0eaf0fdcdb51a0ee6c3bed624333bff8f946733049380be67ac1c" + +[[package]] +name = "plotters-svg" +version = "0.3.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "521fa9638fa597e1dc53e9412a4f9cefb01187ee1f7413076f9e6749e2885ba9" +dependencies = [ + "plotters-backend", +] [[package]] name = "polar-core" @@ -2755,6 +2895,12 @@ dependencies = [ "regex-syntax", ] +[[package]] +name = "regex-automata" +version = "0.1.10" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "6c230d73fb8d8c1b9c0b3135c5142a8acee3a0558fb8db5cf1cb65f8d7862132" + [[package]] name = "regex-syntax" version = "0.6.25" @@ -2852,6 +2998,15 @@ dependencies = [ "semver 0.9.0", ] +[[package]] +name = "rustc_version" +version = "0.4.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "bfa0f585226d2e68097d4f95d113b15b83a82e819ab25717ec0590d9584ef366" +dependencies = [ + "semver 1.0.4", +] + [[package]] name = "rustfmt-wrapper" version = "0.1.0" @@ -2886,9 +3041,9 @@ dependencies = [ [[package]] name = "rustversion" -version = "1.0.5" +version = "1.0.6" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "61b3909d758bb75c79f23d4736fac9433868679d3ad2ea7a61e3c25cfda9a088" +checksum = "f2cc38e8fa666e2de3c4aba7edeb5ffc5246c1c2ed0e3d17e560aeeba736b23f" [[package]] name = "ryu" @@ -3014,6 +3169,12 @@ dependencies = [ "semver-parser 0.10.2", ] +[[package]] +name = "semver" +version = "1.0.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "568a8e6258aa33c13358f81fd834adb854c6f7c9468520910a9b1e8fac068012" + [[package]] name = "semver-parser" version = "0.7.0" @@ -3235,9 +3396,9 @@ dependencies = [ [[package]] name = "signal-hook" -version = "0.3.10" +version = "0.3.12" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9c98891d737e271a2954825ef19e46bd16bdb98e2746f2eec4f7a4ef7946efd1" +checksum = "c35dfd12afb7828318348b8c408383cf5071a086c1d4ab1c0f9840ec92dbb922" dependencies = [ "libc", "signal-hook-registry", @@ -3777,6 +3938,16 @@ dependencies = [ "crunchy", ] +[[package]] +name = "tinytemplate" +version = "1.2.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "be4d6b5f19ff7664e8c98d03e2139cb510db9b0a60b55f8e8709b689d939b6bc" +dependencies = [ + "serde", + "serde_json", +] + [[package]] name = "tinyvec" version = "1.5.1" @@ -4015,7 +4186,7 @@ checksum = "b63708a265f51345575b27fe43f9500ad611579e764c79edbc2037b1121959ec" [[package]] name = "typify" version = "0.0.6-dev" -source = "git+https://github.com/oxidecomputer/typify#5132e748f91311aadd56011b97f51c4f32373985" +source = "git+https://github.com/oxidecomputer/typify#80b510b02b1db22de463efcf6e7762243bcea67a" dependencies = [ "typify-impl", "typify-macro", @@ -4024,7 +4195,7 @@ dependencies = [ [[package]] name = "typify-impl" version = "0.0.6-dev" -source = "git+https://github.com/oxidecomputer/typify#5132e748f91311aadd56011b97f51c4f32373985" +source = "git+https://github.com/oxidecomputer/typify#80b510b02b1db22de463efcf6e7762243bcea67a" dependencies = [ "convert_case", "proc-macro2", @@ -4039,7 +4210,7 @@ dependencies = [ [[package]] name = "typify-macro" version = "0.0.6-dev" -source = "git+https://github.com/oxidecomputer/typify#5132e748f91311aadd56011b97f51c4f32373985" +source = "git+https://github.com/oxidecomputer/typify#80b510b02b1db22de463efcf6e7762243bcea67a" dependencies = [ "proc-macro2", "quote", diff --git a/nexus/Cargo.toml b/nexus/Cargo.toml index d6db89b61f8..57720d9daf7 100644 --- a/nexus/Cargo.toml +++ b/nexus/Cargo.toml @@ -100,8 +100,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" } @@ -111,9 +112,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 diff --git a/nexus/benches/setup_benchmark.rs b/nexus/benches/setup_benchmark.rs new file mode 100644 index 00000000000..738c2733109 --- /dev/null +++ b/nexus/benches/setup_benchmark.rs @@ -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); diff --git a/nexus/test-utils/Cargo.toml b/nexus/test-utils/Cargo.toml new file mode 100644 index 00000000000..5857bca9ab3 --- /dev/null +++ b/nexus/test-utils/Cargo.toml @@ -0,0 +1,26 @@ +[package] +name = "nexus-test-utils" +version = "0.1.0" +edition = "2018" +license = "MPL-2.0" + +[dependencies] +anyhow = "1.0" +bytes = "1.0.1" +chrono = { version = "0.4", features = [ "serde" ] } +dropshot = { git = "https://github.com/oxidecomputer/dropshot", branch = "main" } +http = "0.2.5" +hyper = "0.14" +omicron-common = { path = "../../common" } +omicron-nexus = { path = ".." } +omicron-sled-agent = { path = "../../sled-agent" } +omicron-test-utils = { path = "../../test-utils" } +oximeter = { version = "0.1.0", path = "../../oximeter/oximeter" } +oximeter-client = { path = "../../oximeter-client" } +oximeter-collector = { version = "0.1.0", path = "../../oximeter/collector" } +oximeter-producer = { version = "0.1.0", path = "../../oximeter/producer" } +parse-display = "0.5.3" +serde = { version = "1.0", features = [ "derive" ] } +serde_json = "1.0" +slog = { version = "2.7", features = [ "max_level_trace", "release_max_level_debug" ] } +uuid = { version = "0.8", features = [ "serde", "v4" ] } diff --git a/nexus/tests/common/http_testing.rs b/nexus/test-utils/src/http_testing.rs similarity index 100% rename from nexus/tests/common/http_testing.rs rename to nexus/test-utils/src/http_testing.rs diff --git a/nexus/tests/common/mod.rs b/nexus/test-utils/src/lib.rs similarity index 99% rename from nexus/tests/common/mod.rs rename to nexus/test-utils/src/lib.rs index d47ca194652..46eff37f8a8 100644 --- a/nexus/tests/common/mod.rs +++ b/nexus/test-utils/src/lib.rs @@ -2,9 +2,7 @@ // 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/. -/*! - * Shared integration testing facilities - */ +//! Integration testing facilities for Nexus use dropshot::test_util::ClientTestContext; use dropshot::test_util::LogContext; diff --git a/nexus/tests/common/resource_helpers.rs b/nexus/test-utils/src/resource_helpers.rs similarity index 100% rename from nexus/tests/common/resource_helpers.rs rename to nexus/test-utils/src/resource_helpers.rs diff --git a/nexus/tests/test_authn_http.rs b/nexus/tests/test_authn_http.rs index 07adc70268e..a68d6040d5a 100644 --- a/nexus/tests/test_authn_http.rs +++ b/nexus/tests/test_authn_http.rs @@ -8,8 +8,6 @@ // a lower-level interface, since our hyper Client will not allow us to send // such invalid requests. -pub mod common; - use async_trait::async_trait; use chrono::{DateTime, Duration, Utc}; use dropshot::endpoint; @@ -270,7 +268,7 @@ async fn start_whoami_server( authn_schemes_configured: Vec>>, sessions: HashMap, ) -> TestContext { - let config = common::load_test_config(); + let config = nexus_test_utils::load_test_config(); let logctx = LogContext::new(test_name, &config.log); let whoami_api = { diff --git a/nexus/tests/test_authz.rs b/nexus/tests/test_authz.rs index 928e83b9be5..adbad909f46 100644 --- a/nexus/tests/test_authz.rs +++ b/nexus/tests/test_authz.rs @@ -3,13 +3,12 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. //! Basic end-to-end tests for authorization -use common::http_testing::RequestBuilder; use dropshot::HttpErrorResponseBody; +use nexus_test_utils::http_testing::RequestBuilder; -pub mod common; -use common::test_setup; use http::method::Method; use http::StatusCode; +use nexus_test_utils::test_setup; use omicron_common::api::external::IdentityMetadataCreateParams; use omicron_nexus::authn::external::spoof::HTTP_HEADER_OXIDE_AUTHN_SPOOF; use omicron_nexus::external_api::params; diff --git a/nexus/tests/test_basic.rs b/nexus/tests/test_basic.rs index b71a8533307..8f779af533c 100644 --- a/nexus/tests/test_basic.rs +++ b/nexus/tests/test_basic.rs @@ -27,14 +27,13 @@ use omicron_nexus::external_api::{ use serde::Serialize; use uuid::Uuid; -pub mod common; -use common::http_testing::AuthnMode; -use common::http_testing::NexusRequest; -use common::http_testing::RequestBuilder; -use common::resource_helpers::create_organization; -use common::resource_helpers::create_project; -use common::start_sled_agent; -use common::test_setup; +use nexus_test_utils::http_testing::AuthnMode; +use nexus_test_utils::http_testing::NexusRequest; +use nexus_test_utils::http_testing::RequestBuilder; +use nexus_test_utils::resource_helpers::create_organization; +use nexus_test_utils::resource_helpers::create_project; +use nexus_test_utils::start_sled_agent; +use nexus_test_utils::test_setup; #[macro_use] extern crate slog; diff --git a/nexus/tests/test_console_api.rs b/nexus/tests/test_console_api.rs index 0a66c7aa5fe..ab6ba30101c 100644 --- a/nexus/tests/test_console_api.rs +++ b/nexus/tests/test_console_api.rs @@ -7,9 +7,8 @@ use http::header::HeaderName; use http::{header, method::Method, StatusCode}; use std::env::current_dir; -pub mod common; -use common::http_testing::{RequestBuilder, TestResponse}; -use common::{load_test_config, test_setup, test_setup_with_config}; +use nexus_test_utils::http_testing::{RequestBuilder, TestResponse}; +use nexus_test_utils::{load_test_config, test_setup, test_setup_with_config}; use omicron_common::api::external::IdentityMetadataCreateParams; use omicron_nexus::external_api::console_api::LoginParams; use omicron_nexus::external_api::params::OrganizationCreate; diff --git a/nexus/tests/test_datasets.rs b/nexus/tests/test_datasets.rs index 9d61323a10a..f25e129c2fd 100644 --- a/nexus/tests/test_datasets.rs +++ b/nexus/tests/test_datasets.rs @@ -11,8 +11,7 @@ use omicron_nexus::internal_api::params::{ use std::net::{IpAddr, Ipv4Addr, SocketAddr}; use uuid::Uuid; -pub mod common; -use common::{test_setup, SLED_AGENT_UUID}; +use nexus_test_utils::{test_setup, SLED_AGENT_UUID}; extern crate slog; diff --git a/nexus/tests/test_disks.rs b/nexus/tests/test_disks.rs index e3067644a4e..9bac547b227 100644 --- a/nexus/tests/test_disks.rs +++ b/nexus/tests/test_disks.rs @@ -27,14 +27,13 @@ use dropshot::test_util::objects_post; use dropshot::test_util::read_json; use dropshot::test_util::ClientTestContext; -pub mod common; -use common::http_testing::AuthnMode; -use common::http_testing::NexusRequest; -use common::http_testing::RequestBuilder; -use common::identity_eq; -use common::resource_helpers::create_organization; -use common::resource_helpers::create_project; -use common::test_setup; +use nexus_test_utils::http_testing::AuthnMode; +use nexus_test_utils::http_testing::NexusRequest; +use nexus_test_utils::http_testing::RequestBuilder; +use nexus_test_utils::identity_eq; +use nexus_test_utils::resource_helpers::create_organization; +use nexus_test_utils::resource_helpers::create_project; +use nexus_test_utils::test_setup; /* * TODO-cleanup the mess of URLs used here and in test_instances.rs ought to @@ -88,7 +87,9 @@ async fn test_disks() { snapshot_id: None, size: ByteCount::from_gibibytes_u32(1), }; + println!("POSTING A DISK"); let disk: Disk = objects_post(&client, &url_disks, new_disk.clone()).await; + println!("POSTED A DISK"); assert_eq!(disk.identity.name, "just-rainsticks"); assert_eq!(disk.identity.description, "sells rainsticks"); assert_eq!(disk.project_id, project.identity.id); diff --git a/nexus/tests/test_instances.rs b/nexus/tests/test_instances.rs index 305dc013846..0a6725871f8 100644 --- a/nexus/tests/test_instances.rs +++ b/nexus/tests/test_instances.rs @@ -26,10 +26,9 @@ use dropshot::test_util::objects_post; use dropshot::test_util::read_json; use dropshot::test_util::ClientTestContext; -pub mod common; -use common::identity_eq; -use common::resource_helpers::{create_organization, create_project}; -use common::test_setup; +use nexus_test_utils::identity_eq; +use nexus_test_utils::resource_helpers::{create_organization, create_project}; +use nexus_test_utils::test_setup; static ORGANIZATION_NAME: &str = "test-org"; static PROJECT_NAME: &str = "springfield-squidport"; diff --git a/nexus/tests/test_organizations.rs b/nexus/tests/test_organizations.rs index 96cbbeb518a..396e82ea9d7 100644 --- a/nexus/tests/test_organizations.rs +++ b/nexus/tests/test_organizations.rs @@ -6,13 +6,12 @@ use omicron_nexus::external_api::views::Organization; use dropshot::test_util::{object_delete, object_get}; -pub mod common; -use common::resource_helpers::{ - create_organization, create_project, objects_list_page_authz, -}; -use common::test_setup; use http::method::Method; use http::StatusCode; +use nexus_test_utils::resource_helpers::{ + create_organization, create_project, objects_list_page_authz, +}; +use nexus_test_utils::test_setup; extern crate slog; diff --git a/nexus/tests/test_oximeter.rs b/nexus/tests/test_oximeter.rs index 17b65e6d09c..fdaef0d8e0b 100644 --- a/nexus/tests/test_oximeter.rs +++ b/nexus/tests/test_oximeter.rs @@ -4,8 +4,6 @@ //! Integration tests for oximeter collectors and producers. -pub mod common; - use omicron_test_utils::dev::poll::{wait_for_condition, CondCheckError}; use oximeter_db::DbWrite; use std::net; @@ -14,7 +12,8 @@ use uuid::Uuid; #[tokio::test] async fn test_oximeter_database_records() { - let context = common::test_setup("test_oximeter_database_records").await; + let context = + nexus_test_utils::test_setup("test_oximeter_database_records").await; let db = &context.database; // Get a handle to the DB, for various tests @@ -33,7 +32,7 @@ async fn test_oximeter_database_records() { let actual_id = result[0].get::<&str, Uuid>("id"); assert_eq!( actual_id, - common::OXIMETER_UUID.parse().unwrap(), + nexus_test_utils::OXIMETER_UUID.parse().unwrap(), "Oximeter ID does not match the ID returned from the database" ); @@ -50,13 +49,13 @@ async fn test_oximeter_database_records() { let actual_id = result[0].get::<&str, Uuid>("id"); assert_eq!( actual_id, - common::PRODUCER_UUID.parse().unwrap(), + nexus_test_utils::PRODUCER_UUID.parse().unwrap(), "Producer ID does not match the ID returned from the database" ); let actual_oximeter_id = result[0].get::<&str, Uuid>("oximeter_id"); assert_eq!( actual_oximeter_id, - common::OXIMETER_UUID.parse().unwrap(), + nexus_test_utils::OXIMETER_UUID.parse().unwrap(), "Producer's oximeter ID returned from the database does not match the expected ID" ); @@ -65,10 +64,11 @@ async fn test_oximeter_database_records() { #[tokio::test] async fn test_oximeter_reregistration() { - let mut context = common::test_setup("test_oximeter_reregistration").await; + let mut context = + nexus_test_utils::test_setup("test_oximeter_reregistration").await; let db = &context.database; - let producer_id = common::PRODUCER_UUID.parse().unwrap(); - let oximeter_id = common::OXIMETER_UUID.parse().unwrap(); + let producer_id = nexus_test_utils::PRODUCER_UUID.parse().unwrap(); + let oximeter_id = nexus_test_utils::OXIMETER_UUID.parse().unwrap(); // Get a handle to the DB, for various tests let conn = db.connect().await.unwrap(); @@ -157,9 +157,9 @@ async fn test_oximeter_reregistration() { // Restart the producer, and verify that we have _more_ data than before // Set up a test metric producer server - context.producer = common::start_producer_server( + context.producer = nexus_test_utils::start_producer_server( context.server.http_server_internal.local_addr(), - common::PRODUCER_UUID.parse().unwrap(), + nexus_test_utils::PRODUCER_UUID.parse().unwrap(), ) .await .expect("Failed to restart metric producer server"); @@ -229,7 +229,7 @@ async fn test_oximeter_reregistration() { let timeseries = new_timeseries; // Restart oximeter again, and verify that we have even more new data. - context.oximeter = common::start_oximeter( + context.oximeter = nexus_test_utils::start_oximeter( context.server.http_server_internal.local_addr(), context.clickhouse.port(), oximeter_id, diff --git a/nexus/tests/test_projects.rs b/nexus/tests/test_projects.rs index 05288ee142e..7efa39a0909 100644 --- a/nexus/tests/test_projects.rs +++ b/nexus/tests/test_projects.rs @@ -7,9 +7,8 @@ use omicron_nexus::external_api::views::Project; use dropshot::test_util::object_get; use dropshot::test_util::objects_list_page; -pub mod common; -use common::resource_helpers::{create_organization, create_project}; -use common::test_setup; +use nexus_test_utils::resource_helpers::{create_organization, create_project}; +use nexus_test_utils::test_setup; extern crate slog; diff --git a/nexus/tests/test_router_routes.rs b/nexus/tests/test_router_routes.rs index e7ae6e72df5..44ba08941b2 100644 --- a/nexus/tests/test_router_routes.rs +++ b/nexus/tests/test_router_routes.rs @@ -2,22 +2,21 @@ // 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/. -pub mod common; use std::net::{IpAddr, Ipv4Addr}; -use common::test_setup; use dropshot::test_util::{ object_delete, object_get, objects_list_page, objects_post, }; use dropshot::Method; use http::StatusCode; +use nexus_test_utils::test_setup; use omicron_common::api::external::{ IdentityMetadataCreateParams, IdentityMetadataUpdateParams, Name, RouteDestination, RouteTarget, RouterRoute, RouterRouteCreateParams, RouterRouteKind, RouterRouteUpdateParams, }; -use crate::common::resource_helpers::{ +use nexus_test_utils::resource_helpers::{ create_organization, create_project, create_router, create_vpc, }; diff --git a/nexus/tests/test_users_builtin.rs b/nexus/tests/test_users_builtin.rs index c75842ac07e..245d25672e8 100644 --- a/nexus/tests/test_users_builtin.rs +++ b/nexus/tests/test_users_builtin.rs @@ -5,11 +5,10 @@ use http::Method; use http::StatusCode; use std::collections::BTreeMap; -pub mod common; -use common::http_testing::AuthnMode; -use common::http_testing::NexusRequest; -use common::http_testing::RequestBuilder; -use common::test_setup; +use nexus_test_utils::http_testing::AuthnMode; +use nexus_test_utils::http_testing::NexusRequest; +use nexus_test_utils::http_testing::RequestBuilder; +use nexus_test_utils::test_setup; use omicron_nexus::authn; use omicron_nexus::external_api::views::User; diff --git a/nexus/tests/test_vpc_firewall.rs b/nexus/tests/test_vpc_firewall.rs index e966c836bf7..6af4501bc06 100644 --- a/nexus/tests/test_vpc_firewall.rs +++ b/nexus/tests/test_vpc_firewall.rs @@ -16,11 +16,10 @@ use std::convert::TryFrom; use dropshot::test_util::{object_delete, objects_list_page}; -pub mod common; -use common::resource_helpers::{ +use nexus_test_utils::resource_helpers::{ create_organization, create_project, create_vpc, }; -use common::test_setup; +use nexus_test_utils::test_setup; extern crate slog; diff --git a/nexus/tests/test_vpc_routers.rs b/nexus/tests/test_vpc_routers.rs index 81c81f9f2ec..c5ade382093 100644 --- a/nexus/tests/test_vpc_routers.rs +++ b/nexus/tests/test_vpc_routers.rs @@ -14,12 +14,11 @@ use dropshot::test_util::object_get; use dropshot::test_util::objects_list_page; use dropshot::test_util::objects_post; -pub mod common; -use common::identity_eq; -use common::resource_helpers::{ +use nexus_test_utils::identity_eq; +use nexus_test_utils::resource_helpers::{ create_organization, create_project, create_vpc, }; -use common::test_setup; +use nexus_test_utils::test_setup; extern crate slog; diff --git a/nexus/tests/test_vpc_subnets.rs b/nexus/tests/test_vpc_subnets.rs index d93bf8b0e31..25324e8c93a 100644 --- a/nexus/tests/test_vpc_subnets.rs +++ b/nexus/tests/test_vpc_subnets.rs @@ -16,12 +16,11 @@ use dropshot::test_util::objects_list_page; use dropshot::test_util::objects_post; use dropshot::test_util::ClientTestContext; -pub mod common; -use common::identity_eq; -use common::resource_helpers::{ +use nexus_test_utils::identity_eq; +use nexus_test_utils::resource_helpers::{ create_organization, create_project, create_vpc, }; -use common::test_setup; +use nexus_test_utils::test_setup; extern crate slog; diff --git a/nexus/tests/test_vpcs.rs b/nexus/tests/test_vpcs.rs index 2e4355edc96..3a2a2a4c49f 100644 --- a/nexus/tests/test_vpcs.rs +++ b/nexus/tests/test_vpcs.rs @@ -11,12 +11,11 @@ use dropshot::test_util::object_get; use dropshot::test_util::objects_list_page; use dropshot::test_util::ClientTestContext; -pub mod common; -use common::identity_eq; -use common::resource_helpers::{ +use nexus_test_utils::identity_eq; +use nexus_test_utils::resource_helpers::{ create_organization, create_project, create_vpc, create_vpc_with_error, }; -use common::test_setup; +use nexus_test_utils::test_setup; extern crate slog; diff --git a/nexus/tests/test_zpools.rs b/nexus/tests/test_zpools.rs index ae88667f42e..67095973bd4 100644 --- a/nexus/tests/test_zpools.rs +++ b/nexus/tests/test_zpools.rs @@ -8,8 +8,7 @@ use omicron_common::api::external::ByteCount; use omicron_nexus::internal_api::params::ZpoolPutRequest; use uuid::Uuid; -pub mod common; -use common::{test_setup, SLED_AGENT_UUID}; +use nexus_test_utils::{test_setup, SLED_AGENT_UUID}; extern crate slog; From 444aaa054c0da62b6a820487358b05fda537d01d Mon Sep 17 00:00:00 2001 From: Sean Klein Date: Wed, 8 Dec 2021 14:24:03 -0500 Subject: [PATCH 2/3] No need to be screamy about disk posting, that's for another PR --- nexus/tests/test_disks.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/nexus/tests/test_disks.rs b/nexus/tests/test_disks.rs index 9bac547b227..88142097742 100644 --- a/nexus/tests/test_disks.rs +++ b/nexus/tests/test_disks.rs @@ -87,9 +87,7 @@ async fn test_disks() { snapshot_id: None, size: ByteCount::from_gibibytes_u32(1), }; - println!("POSTING A DISK"); let disk: Disk = objects_post(&client, &url_disks, new_disk.clone()).await; - println!("POSTED A DISK"); assert_eq!(disk.identity.name, "just-rainsticks"); assert_eq!(disk.identity.description, "sells rainsticks"); assert_eq!(disk.project_id, project.identity.id); From 54b6f68364914dead2c683ca9600cce295406d59 Mon Sep 17 00:00:00 2001 From: Sean Klein Date: Wed, 8 Dec 2021 20:36:46 -0500 Subject: [PATCH 3/3] Add to top-level workspace --- Cargo.toml | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Cargo.toml b/Cargo.toml index 336b9e22b90..5435afd0169 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -3,6 +3,7 @@ members = [ "common", "nexus", "nexus/src/db/db-macros", + "nexus/test-utils", "nexus-client", "package", "rpaths", @@ -22,6 +23,7 @@ default-members = [ "common", "nexus", "nexus/src/db/db-macros", + "nexus/test-utils", "package", "rpaths", "sled-agent",