fix: Create the test database as part of ng server fixture startup
parent
e4fb227c6e
commit
93b0cdbcc4
.circleci
influxdb_iox
tests/common_ng
iox_catalog
|
@ -240,8 +240,6 @@ jobs:
|
|||
- checkout
|
||||
- rust_components
|
||||
- cache_restore
|
||||
- run: cargo install sqlx-cli
|
||||
- run: DATABASE_URL=${TEST_INFLUXDB_IOX_CATALOG_DSN} sqlx database create
|
||||
- run: INFLUXDB_IOX_CATALOG_DSN=${TEST_INFLUXDB_IOX_CATALOG_DSN} cargo run -- catalog setup
|
||||
- run:
|
||||
name: Cargo test
|
||||
|
|
|
@ -2141,6 +2141,7 @@ dependencies = [
|
|||
"serde_urlencoded",
|
||||
"server",
|
||||
"snafu",
|
||||
"sqlx",
|
||||
"tempfile",
|
||||
"test_helpers",
|
||||
"thiserror",
|
||||
|
|
|
@ -119,6 +119,7 @@ predicates = "2.1.0"
|
|||
rand = "0.8.3"
|
||||
regex = "1"
|
||||
reqwest = { version = "0.11", default-features = false, features = ["json", "rustls-tls"] }
|
||||
sqlx = { version = "0.5", features = [ "runtime-tokio-rustls" , "postgres", "uuid" ] }
|
||||
tempfile = "3.1.0"
|
||||
|
||||
[features]
|
||||
|
|
|
@ -49,7 +49,8 @@ macro_rules! maybe_skip_integration {
|
|||
|
||||
return;
|
||||
} else {
|
||||
env::var("TEST_INFLUXDB_IOX_CATALOG_DSN").expect("already checked TEST_INFLUXDB_IOX_CATALOG_DSN")
|
||||
env::var("TEST_INFLUXDB_IOX_CATALOG_DSN")
|
||||
.expect("already checked TEST_INFLUXDB_IOX_CATALOG_DSN")
|
||||
}
|
||||
}};
|
||||
}
|
||||
|
|
|
@ -2,6 +2,7 @@ use assert_cmd::prelude::*;
|
|||
use futures::prelude::*;
|
||||
use http::{header::HeaderName, HeaderValue};
|
||||
use influxdb_iox_client::connection::Connection;
|
||||
use sqlx::{migrate::MigrateDatabase, Postgres};
|
||||
use std::{
|
||||
net::SocketAddrV4,
|
||||
path::Path,
|
||||
|
@ -89,7 +90,7 @@ impl ServerFixture {
|
|||
/// Create a new server fixture with the provided additional environment variables
|
||||
/// and wait for it to be ready. The server is not shared with any other tests.
|
||||
pub async fn create_single_use_with_config(test_config: TestConfig) -> Self {
|
||||
let server = TestServer::new(test_config);
|
||||
let server = TestServer::new(test_config).await;
|
||||
let server = Arc::new(server);
|
||||
|
||||
// ensure the server is ready
|
||||
|
@ -222,13 +223,13 @@ impl TestConfig {
|
|||
/// Set Postgres catalog DSN URL
|
||||
pub fn with_postgres_catalog(mut self, dsn: &str) -> Self {
|
||||
self.dsn = Some(dsn.into());
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
// Get the catalog DSN URL and panic if it's not set
|
||||
fn dsn(&self) -> &str {
|
||||
self
|
||||
.dsn
|
||||
self.dsn
|
||||
.as_ref()
|
||||
.expect("Test Config must have a catalog configured")
|
||||
}
|
||||
|
@ -255,19 +256,22 @@ struct Process {
|
|||
}
|
||||
|
||||
impl TestServer {
|
||||
fn new(test_config: TestConfig) -> Self {
|
||||
async fn new(test_config: TestConfig) -> Self {
|
||||
let addrs = BindAddresses::default();
|
||||
let ready = Mutex::new(ServerState::Started);
|
||||
|
||||
let dir = test_helpers::tmp_dir().unwrap();
|
||||
|
||||
let server_process = Mutex::new(Self::create_server_process(
|
||||
&addrs,
|
||||
&dir,
|
||||
test_config.dsn(),
|
||||
&test_config.env,
|
||||
test_config.server_type,
|
||||
));
|
||||
let server_process = Mutex::new(
|
||||
Self::create_server_process(
|
||||
&addrs,
|
||||
&dir,
|
||||
test_config.dsn(),
|
||||
&test_config.env,
|
||||
test_config.server_type,
|
||||
)
|
||||
.await,
|
||||
);
|
||||
|
||||
Self {
|
||||
ready,
|
||||
|
@ -289,11 +293,12 @@ impl TestServer {
|
|||
self.test_config.dsn(),
|
||||
&self.test_config.env,
|
||||
self.test_config.server_type,
|
||||
);
|
||||
)
|
||||
.await;
|
||||
*ready_guard = ServerState::Started;
|
||||
}
|
||||
|
||||
fn create_server_process(
|
||||
async fn create_server_process(
|
||||
addrs: &BindAddresses,
|
||||
dir: &TempDir,
|
||||
dsn: &str,
|
||||
|
@ -328,6 +333,11 @@ impl TestServer {
|
|||
ServerType::Router2 => "router2",
|
||||
};
|
||||
|
||||
// Create the catalog database if it doesn't exist
|
||||
if !Postgres::database_exists(dsn).await.unwrap() {
|
||||
Postgres::create_database(dsn).await.unwrap();
|
||||
}
|
||||
|
||||
// This will inherit environment from the test runner
|
||||
// in particular `LOG_FILTER`
|
||||
let child = Command::cargo_bin("influxdb_iox")
|
||||
|
|
|
@ -52,12 +52,6 @@ DIFFERENT database name for your test database than your `INFLUXDB_IOX_CATALOG_D
|
|||
|
||||
* Set `TEST_INFLUXDB_IOX_CATALOG_DSN=<testdsn>` env as above with the `INFLUXDB_IOX_CATALOG_DSN`
|
||||
env var. The integration tests *will* pick up this value if set in your `.env` file.
|
||||
* Create the test database once by running:
|
||||
|
||||
```
|
||||
DATABASE_URL=<testdsn> sqlx database create
|
||||
```
|
||||
|
||||
* Set up the test database as above but specify the test database URL as follows (`catalog setup`
|
||||
will NOT pick up the `TEST_` version of the environment variable from your `.env` file so it
|
||||
needs to be specified explicitly WITHOUT the `TEST_` prefix):
|
||||
|
|
Loading…
Reference in New Issue