Skip to content

Commit

Permalink
Ensure db-init files are disjoint
Browse files Browse the repository at this point in the history
  • Loading branch information
andrewjstone committed Jul 25, 2024
1 parent e5b45e0 commit 85816dd
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
/*
* A test implementation of `db-init.sql` that only includes a few metric types.
* The purpose of this is to reduce test startup time.
*/
CREATE DATABASE IF NOT EXISTS oximeter ON CLUSTER oximeter_cluster;

/* The version table contains metadata about the `oximeter` database */
Expand Down
File renamed without changes.
15 changes: 13 additions & 2 deletions oximeter/db/src/client/dbwrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,20 @@ impl DbWrite for Client {
}

/// Initialize the replicated telemetry database, creating tables as needed.
///
/// We run both db-init files since we want all tables in production.
/// These files are intentionally disjoint so that we don't have to
/// duplicate any setup.
async fn init_replicated_db(&self) -> Result<(), Error> {
debug!(self.log, "initializing ClickHouse database");
self.run_many_sql_statements(include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/schema/replicated/db-init.sql"
"/schema/replicated/db-init-1.sql"
)))
.await?;
self.run_many_sql_statements(include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/schema/replicated/db-init-2.sql"
)))
.await
}
Expand Down Expand Up @@ -110,11 +119,13 @@ pub trait TestDbWrite {
#[async_trait::async_trait]
impl TestDbWrite for Client {
/// Initialize the replicated telemetry database, creating tables as needed.
/// We run only the first db-init file, since it contains a minimum number
/// of tables required for replication/cluster tests.
async fn init_test_minimal_replicated_db(&self) -> Result<(), Error> {
debug!(self.log, "initializing ClickHouse database");
self.run_many_sql_statements(include_str!(concat!(
env!("CARGO_MANIFEST_DIR"),
"/schema/replicated/db-init-test.sql"
"/schema/replicated/db-init-1.sql"
)))
.await
}
Expand Down
2 changes: 1 addition & 1 deletion oximeter/db/tests/integration_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,8 @@ impl TestInput {

#[tokio::test]
async fn test_cluster() -> anyhow::Result<()> {
let request_timeout = Duration::from_secs(15);
usdt::register_probes().unwrap();
let request_timeout = Duration::from_secs(15);
let start = tokio::time::Instant::now();
let logctx = test_setup_log("test_cluster");
let log = &logctx.log;
Expand Down

0 comments on commit 85816dd

Please sign in to comment.