Skip to content
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

Use TestDatabase outside of nexus-db-queries too #6893

Merged
merged 34 commits into from
Oct 30, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
6a3020e
pin qorb's revision
smklein Oct 15, 2024
b9bf692
hakariiiiiii
smklein Oct 15, 2024
d338e92
wip
smklein Oct 15, 2024
d1d8f22
Merge branch 'main' into qorb-pin
smklein Oct 15, 2024
41a930d
Merge branch 'qorb-pin' into qorb-terminate
smklein Oct 15, 2024
ffcdada
Use explicit revs
smklein Oct 15, 2024
968b8da
Explicit pool destructor, panic if not called
smklein Oct 15, 2024
10a647c
Add timeout as tunable for initialization, qorb 0.1.0
smklein Oct 16, 2024
fcedb8d
Stop internal server (and pool) during builder teardown
smklein Oct 16, 2024
83d22d6
Merge branch 'main' into qorb-terminate, also fix more tests
smklein Oct 16, 2024
7f2b2bd
De-duplicate Nexus termination code
smklein Oct 16, 2024
6326cde
Panic like a pro (thanks john)
smklein Oct 16, 2024
a8a27cc
Merge branch 'main' into qorb-terminate
smklein Oct 16, 2024
320960f
Use a test wrapper for DB work in db-queries
smklein Oct 17, 2024
168fdfa
merge errors
smklein Oct 17, 2024
144d5ea
Stop CRDB in one of the volume tests
smklein Oct 17, 2024
ed21f58
Use TestDatabase outside of nexus-db-queries too
smklein Oct 17, 2024
95c6825
review feedback
smklein Oct 17, 2024
6d2673b
update qorb revision
smklein Oct 18, 2024
0d59b62
state -> kind
smklein Oct 18, 2024
2c082c1
Merge branch 'main' into qorb-terminate
smklein Oct 18, 2024
350d70e
Update datastore_test api (mergin')
smklein Oct 18, 2024
74d0fdb
Convert a new test
smklein Oct 18, 2024
7a5dbb2
Merge branch 'qorb-terminate' into more-test-database
smklein Oct 18, 2024
22ae5d5
Fix path
smklein Oct 18, 2024
f672ca4
Terminate the pool
smklein Oct 18, 2024
e707cc5
Merge branch 'main' into qorb-terminate
smklein Oct 18, 2024
67bc389
Merge branch 'qorb-terminate' into more-test-database
smklein Oct 18, 2024
3a7b9f5
Merge branch 'main' into qorb-terminate
smklein Oct 22, 2024
904d837
Merge branch 'qorb-terminate' into more-test-database
smklein Oct 22, 2024
972dc6c
Merge branch 'main' into qorb-terminate
smklein Oct 28, 2024
5da9f5d
Merge branch 'qorb-terminate' into more-test-database
smklein Oct 28, 2024
c15c1f9
feedback
smklein Oct 30, 2024
f78d2bb
fix cockroach-admin tests, private builder
smklein Oct 30, 2024
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
14 changes: 7 additions & 7 deletions cockroach-admin/src/cockroach_cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -137,7 +137,7 @@ impl CockroachCli {
mod tests {
use super::*;
use cockroach_admin_types::NodeMembership;
use nexus_test_utils::db::test_setup_database;
use nexus_test_utils::db::TestDatabase;
use omicron_test_utils::dev;
use std::net::SocketAddr;
use url::Url;
Expand Down Expand Up @@ -179,8 +179,8 @@ mod tests {
#[tokio::test]
async fn test_node_status_compatibility() {
let logctx = dev::test_setup_log("test_node_status_compatibility");
let mut db = test_setup_database(&logctx.log).await;
let db_url = db.listen_url().to_string();
let db = TestDatabase::new_without_schema(&logctx.log).await;
let db_url = db.crdb().listen_url().to_string();

let expected_headers = "id,address,sql_address,build,started_at,updated_at,locality,is_available,is_live";

Expand Down Expand Up @@ -225,7 +225,7 @@ mod tests {
assert_eq!(status[0].is_available, true);
assert_eq!(status[0].is_live, true);

db.cleanup().await.unwrap();
db.terminate().await;
logctx.cleanup_successful();
}

Expand All @@ -236,8 +236,8 @@ mod tests {
async fn test_node_decommission_compatibility() {
let logctx =
dev::test_setup_log("test_node_decommission_compatibility");
let mut db = test_setup_database(&logctx.log).await;
let db_url = db.listen_url().to_string();
let db = TestDatabase::new_without_schema(&logctx.log).await;
let db_url = db.crdb().listen_url().to_string();

let expected_headers =
"id,is_live,replicas,is_decommissioning,membership,is_draining";
Expand Down Expand Up @@ -291,7 +291,7 @@ mod tests {
assert_eq!(result.is_draining, false);
assert_eq!(result.notes, &[] as &[&str]);

db.cleanup().await.unwrap();
db.terminate().await;
logctx.cleanup_successful();
}
}
9 changes: 5 additions & 4 deletions cockroach-admin/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -138,18 +138,19 @@ impl ServerContext {
#[cfg(test)]
mod tests {
use super::*;
use nexus_test_utils::db::test_setup_database;
use nexus_test_utils::db::TestDatabase;
use omicron_test_utils::dev;
use std::net::SocketAddrV6;
use url::Url;

#[tokio::test]
async fn test_node_id() {
let logctx = dev::test_setup_log("test_node_id");
let mut db = test_setup_database(&logctx.log).await;
let db = TestDatabase::new_without_schema(&logctx.log).await;
let crdb = db.crdb();

// Construct a `ServerContext`.
let db_url = db.listen_url().to_string();
let db_url = crdb.listen_url().to_string();
let url: Url = db_url.parse().expect("valid url");
let cockroach_address: SocketAddrV6 = format!(
"{}:{}",
Expand All @@ -173,7 +174,7 @@ mod tests {

// The `OnceCell` should be populated now; even if we shut down the DB,
// we can still fetch the node ID.
db.cleanup().await.unwrap();
db.terminate().await;
let node_id =
context.node_id().await.expect("successfully read node ID");
assert_eq!(node_id, "1");
Expand Down
6 changes: 3 additions & 3 deletions nexus/benches/setup_benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

use criterion::{criterion_group, criterion_main, Criterion};
use dropshot::test_util::LogContext;
use nexus_test_utils::db::test_setup_database;
use nexus_db_queries::db::pub_test_utils::TestDatabase;
use omicron_test_utils::dev;

// This is the default wrapper around most Nexus integration tests.
Expand All @@ -22,8 +22,8 @@ async fn do_full_setup() {
async fn do_crdb_setup() {
let cfg = nexus_test_utils::load_test_config();
let logctx = LogContext::new("crdb_setup", &cfg.pkg.log);
let mut db = test_setup_database(&logctx.log).await;
db.cleanup().await.unwrap();
let db = TestDatabase::new_with_datastore(&logctx.log).await;
db.terminate().await;
}

// Wraps exclusively the ClickhouseDB portion of setup/teardown.
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ omicron-workspace-hack.workspace = true
omicron-test-utils = { workspace = true, optional = true }

[features]
# Enable to export `datastore_test`
# Enable to export `TestDatabase`
testing = ["omicron-test-utils"]

[dev-dependencies]
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/collection_attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -577,8 +577,8 @@ where
#[cfg(test)]
mod test {
use super::*;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::identity::Resource as IdentityResource;
use crate::db::pub_test_utils::TestDatabase;
use async_bb8_diesel::{AsyncRunQueryDsl, AsyncSimpleConnection};
use chrono::Utc;
use db_macros::Resource;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/collection_detach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -481,8 +481,8 @@ where
mod test {
use super::*;
use crate::db::collection_attach::DatastoreAttachTarget;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::identity::Resource as IdentityResource;
use crate::db::pub_test_utils::TestDatabase;
use async_bb8_diesel::{AsyncRunQueryDsl, AsyncSimpleConnection};
use chrono::Utc;
use db_macros::Resource;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/collection_detach_many.rs
Original file line number Diff line number Diff line change
Expand Up @@ -479,8 +479,8 @@ where
mod test {
use super::*;
use crate::db::collection_attach::DatastoreAttachTarget;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::identity::Resource as IdentityResource;
use crate::db::pub_test_utils::TestDatabase;
use async_bb8_diesel::{AsyncRunQueryDsl, AsyncSimpleConnection};
use chrono::Utc;
use db_macros::Resource;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/collection_insert.rs
Original file line number Diff line number Diff line change
Expand Up @@ -405,8 +405,8 @@ where
#[cfg(test)]
mod test {
use super::*;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::identity::Resource as IdentityResource;
use crate::db::pub_test_utils::TestDatabase;
use async_bb8_diesel::{AsyncRunQueryDsl, AsyncSimpleConnection};
use chrono::{DateTime, Utc};
use db_macros::Resource;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/allow_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,8 @@ impl super::DataStore {

#[cfg(test)]
mod tests {
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::fixed_data::allow_list::USER_FACING_SERVICES_ALLOW_LIST_ID;
use crate::db::pub_test_utils::TestDatabase;
use omicron_common::api::external;
use omicron_test_utils::dev;

Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/bgp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1000,7 +1000,7 @@ impl DataStore {
#[cfg(test)]
mod tests {
use super::*;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::pub_test_utils::TestDatabase;
use omicron_common::api::external::IdentityMetadataCreateParams;
use omicron_common::api::external::Name;
use omicron_test_utils::dev;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/clickhouse_policy.rs
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ impl DataStore {
#[cfg(test)]
mod tests {
use super::*;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::pub_test_utils::TestDatabase;
use nexus_inventory::now_db_precision;
use nexus_types::deployment::ClickhouseMode;
use omicron_test_utils::dev;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/cockroachdb_node_id.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ impl DataStore {
#[cfg(test)]
mod tests {
use super::*;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::pub_test_utils::TestDatabase;
use omicron_test_utils::dev;

#[tokio::test]
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/cockroachdb_settings.rs
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ impl DataStore {
#[cfg(test)]
mod test {
use super::CockroachDbSettings;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::pub_test_utils::TestDatabase;
use nexus_types::deployment::CockroachDbClusterVersion;
use omicron_common::api::external::Error;
use omicron_test_utils::dev;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/dataset.rs
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,7 @@ impl DataStore {
#[cfg(test)]
mod test {
use super::*;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::pub_test_utils::TestDatabase;
use nexus_db_model::Generation;
use nexus_db_model::SledBaseboard;
use nexus_db_model::SledSystemHardware;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/db_metadata.rs
Original file line number Diff line number Diff line change
Expand Up @@ -496,7 +496,7 @@ impl DataStore {
#[cfg(test)]
mod test {
use super::*;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::pub_test_utils::TestDatabase;
use camino::Utf8Path;
use camino_tempfile::Utf8TempDir;
use nexus_db_model::SCHEMA_VERSION;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/deployment.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1730,7 +1730,7 @@ impl RunQueryDsl<DbConnection> for InsertTargetQuery {}
mod tests {
use super::*;

use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::pub_test_utils::TestDatabase;
use crate::db::raw_query_builder::QueryBuilder;
use nexus_inventory::now_db_precision;
use nexus_inventory::CollectionBuilder;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -408,7 +408,7 @@ impl DataStore {
#[cfg(test)]
mod tests {
use super::*;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::pub_test_utils::TestDatabase;
use crate::db::queries::ALLOW_FULL_TABLE_SCAN_SQL;
use anyhow::Context as _;
use async_bb8_diesel::AsyncSimpleConnection;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -843,7 +843,7 @@ impl DataStore {
mod tests {
use super::*;

use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::pub_test_utils::TestDatabase;
use nexus_types::external_api::params;
use omicron_common::api::external;
use omicron_test_utils::dev;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/dns.rs
Original file line number Diff line number Diff line change
Expand Up @@ -729,8 +729,8 @@ impl DataStoreDnsTest for DataStore {

#[cfg(test)]
mod test {
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::datastore::DnsVersionUpdateBuilder;
use crate::db::pub_test_utils::TestDatabase;
use crate::db::DataStore;
use crate::db::TransactionError;
use assert_matches::assert_matches;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/external_ip.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1132,7 +1132,7 @@ impl DataStore {
#[cfg(test)]
mod tests {
use super::*;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::pub_test_utils::TestDatabase;
use nexus_types::deployment::OmicronZoneExternalFloatingIp;
use nexus_types::deployment::OmicronZoneExternalSnatIp;
use nexus_types::external_api::shared::IpRange;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/instance.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1943,10 +1943,10 @@ impl DataStore {
#[cfg(test)]
mod tests {
use super::*;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::datastore::sled;
use crate::db::lookup::LookupPath;
use crate::db::pagination::Paginator;
use crate::db::pub_test_utils::TestDatabase;
use nexus_db_model::InstanceState;
use nexus_db_model::Project;
use nexus_db_model::VmmRuntimeState;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/inventory.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2444,8 +2444,8 @@ impl DataStoreInventoryTest for DataStore {
#[cfg(test)]
mod test {
use crate::db::datastore::inventory::DataStoreInventoryTest;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::datastore::DataStoreConnection;
use crate::db::pub_test_utils::TestDatabase;
use crate::db::raw_query_builder::{QueryBuilder, TrustedStr};
use crate::db::schema;
use crate::db::DataStore;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/ip_pool.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1121,10 +1121,10 @@ mod test {
use std::num::NonZeroU32;

use crate::authz;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::model::{
IpPool, IpPoolResource, IpPoolResourceType, Project,
};
use crate::db::pub_test_utils::TestDatabase;
use assert_matches::assert_matches;
use nexus_types::external_api::params;
use nexus_types::identity::Resource;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/ipv4_nat_entry.rs
Original file line number Diff line number Diff line change
Expand Up @@ -379,7 +379,7 @@ fn ipv4_nat_next_version() -> diesel::expression::SqlLiteral<BigInt> {
mod test {
use std::{net::Ipv4Addr, str::FromStr};

use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::pub_test_utils::TestDatabase;
use chrono::Utc;
use nexus_db_model::{Ipv4NatEntry, Ipv4NatValues, MacAddr, Vni};
use omicron_common::api::external;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/migration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,9 @@ impl DataStore {
mod tests {
use super::*;
use crate::authz;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::lookup::LookupPath;
use crate::db::model::Instance;
use crate::db::pub_test_utils::TestDatabase;
use nexus_db_model::Project;
use nexus_types::external_api::params;
use nexus_types::silo::DEFAULT_SILO_ID;
Expand Down
4 changes: 1 addition & 3 deletions nexus/db-queries/src/db/datastore/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,6 @@ mod oximeter;
mod physical_disk;
mod probe;
mod project;
#[cfg(any(test, feature = "testing"))]
pub mod pub_test_utils;
mod quota;
mod rack;
mod region;
Expand Down Expand Up @@ -446,7 +444,6 @@ mod test {
use crate::authn;
use crate::authn::SiloAuthnPolicy;
use crate::authz;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::datastore::test_utils::{
IneligibleSledKind, IneligibleSleds,
};
Expand All @@ -459,6 +456,7 @@ mod test {
Region, SiloUser, SledBaseboard, SledSystemHardware, SledUpdate,
SshKey, Zpool,
};
use crate::db::pub_test_utils::TestDatabase;
use crate::db::queries::vpc_subnet::InsertVpcSubnetQuery;
use chrono::{Duration, Utc};
use futures::stream;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/network_interface.rs
Original file line number Diff line number Diff line change
Expand Up @@ -892,7 +892,7 @@ impl DataStore {
#[cfg(test)]
mod tests {
use super::*;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::pub_test_utils::TestDatabase;
use nexus_config::NUM_INITIAL_RESERVED_IP_ADDRESSES;
use nexus_db_fixed_data::vpc_subnet::NEXUS_VPC_SUBNET;
use omicron_common::address::NEXUS_OPTE_IPV4_SUBNET;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/oximeter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,7 @@ impl DataStore {
#[cfg(test)]
mod tests {
use super::*;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::pub_test_utils::TestDatabase;
use nexus_types::internal_api::params;
use omicron_common::api::internal::nexus;
use omicron_test_utils::dev;
Expand Down
2 changes: 1 addition & 1 deletion nexus/db-queries/src/db/datastore/physical_disk.rs
Original file line number Diff line number Diff line change
Expand Up @@ -321,12 +321,12 @@ impl DataStore {
#[cfg(test)]
mod test {
use super::*;
use crate::db::datastore::pub_test_utils::TestDatabase;
use crate::db::datastore::test::{
sled_baseboard_for_test, sled_system_hardware_for_test,
};
use crate::db::lookup::LookupPath;
use crate::db::model::{PhysicalDiskKind, Sled, SledUpdate};
use crate::db::pub_test_utils::TestDatabase;
use dropshot::PaginationOrder;
use nexus_db_model::Generation;
use nexus_sled_agent_shared::inventory::{
Expand Down
Loading
Loading