diff --git a/scripts/federation.sh b/scripts/federation.sh index ae6cc39..24e925b 100755 --- a/scripts/federation.sh +++ b/scripts/federation.sh @@ -19,7 +19,6 @@ BETA_DB_PATH="$DB_FOLDER/beta" ALPHA_DB_URL="postgresql://ibis:password@/ibis?host=$ALPHA_DB_PATH" BETA_DB_URL="postgresql://ibis:password@/ibis?host=$BETA_DB_PATH" -echo $ALPHA_DB_URL # get rid of processes leftover from previous runs killall ibis || true @@ -31,4 +30,7 @@ CARGO_TARGET_DIR=target/frontend trunk build (trap 'kill 0' SIGINT; sh -c "IBIS__BIND=127.0.0.1:8070 IBIS__FEDERATION__DOMAIN=ibis-alpha:8070 IBIS__DATABASE_URL=$ALPHA_DB_URL cargo run" & sh -c "IBIS__BIND=127.0.0.1:8080 IBIS__FEDERATION__DOMAIN=ibis-beta:8080 IBIS__DATABASE_URL=$BETA_DB_URL cargo run" & -) \ No newline at end of file +) + +./tests/scripts/stop_dev_db.sh $ALPHA_DB_PATH +./tests/scripts/stop_dev_db.sh $BETA_DB_PATH \ No newline at end of file diff --git a/tests/common.rs b/tests/common.rs index 98451cf..8cf60ea 100644 --- a/tests/common.rs +++ b/tests/common.rs @@ -5,7 +5,7 @@ use ibis_lib::frontend::api::ApiClient; use ibis_lib::frontend::error::MyResult; use reqwest::ClientBuilder; use std::env::current_dir; -use std::fs::create_dir_all; +use std::fs::{create_dir_all, remove_dir_all}; use std::ops::Deref; use std::process::{Command, Stdio}; use std::sync::atomic::{AtomicI32, Ordering}; @@ -90,11 +90,15 @@ pub struct IbisInstance { impl IbisInstance { fn prepare_db(db_path: String) -> std::thread::JoinHandle<()> { + // stop any db leftover from previous run + Self::stop_internal(db_path.clone()); + // remove old db + remove_dir_all(&db_path).unwrap(); spawn(move || { Command::new("./tests/scripts/start_dev_db.sh") .arg(&db_path) - .stdout(Stdio::null()) - .stderr(Stdio::null()) + .stdout(Stdio::inherit()) + .stderr(Stdio::inherit()) .output() .unwrap(); }) @@ -135,9 +139,13 @@ impl IbisInstance { fn stop(self) -> std::thread::JoinHandle<()> { self.db_handle.abort(); + Self::stop_internal(self.db_path) + } + + fn stop_internal(db_path: String) -> std::thread::JoinHandle<()> { spawn(move || { Command::new("./tests/scripts/stop_dev_db.sh") - .arg(&self.db_path) + .arg(db_path) .stdout(Stdio::null()) .stderr(Stdio::null()) .output() diff --git a/tests/scripts/start_dev_db.sh b/tests/scripts/start_dev_db.sh index 2f2db9a..250bea4 100755 --- a/tests/scripts/start_dev_db.sh +++ b/tests/scripts/start_dev_db.sh @@ -12,9 +12,6 @@ then pg_ctl stop fi -# Remove any leftover data from revious run -rm -rf $1 - # Create cluster initdb --username=postgres --auth=trust --no-instructions