mirror of
https://github.com/Nutomic/ibis.git
synced 2024-11-29 10:01:10 +00:00
test improvements
This commit is contained in:
parent
851f30dc24
commit
181b585644
4 changed files with 53 additions and 45 deletions
1
Cargo.lock
generated
1
Cargo.lock
generated
|
@ -696,7 +696,6 @@ dependencies = [
|
||||||
"rand",
|
"rand",
|
||||||
"reqwest",
|
"reqwest",
|
||||||
"serde",
|
"serde",
|
||||||
"serde_json",
|
|
||||||
"serial_test",
|
"serial_test",
|
||||||
"sha2",
|
"sha2",
|
||||||
"tokio",
|
"tokio",
|
||||||
|
|
|
@ -19,7 +19,6 @@ env_logger = { version = "0.10.1", default-features = false }
|
||||||
futures = "0.3.29"
|
futures = "0.3.29"
|
||||||
rand = "0.8.5"
|
rand = "0.8.5"
|
||||||
serde = "1.0.192"
|
serde = "1.0.192"
|
||||||
serde_json = "1.0.108"
|
|
||||||
sha2 = "0.10.8"
|
sha2 = "0.10.8"
|
||||||
tokio = { version = "1.34.0", features = ["full"] }
|
tokio = { version = "1.34.0", features = ["full"] }
|
||||||
tracing = "0.1.40"
|
tracing = "0.1.40"
|
||||||
|
|
|
@ -12,6 +12,7 @@ use serde::ser::Serialize;
|
||||||
use std::env::current_dir;
|
use std::env::current_dir;
|
||||||
use std::process::{Command, Stdio};
|
use std::process::{Command, Stdio};
|
||||||
use std::sync::Once;
|
use std::sync::Once;
|
||||||
|
use std::thread::spawn;
|
||||||
use tokio::task::JoinHandle;
|
use tokio::task::JoinHandle;
|
||||||
use tracing::log::LevelFilter;
|
use tracing::log::LevelFilter;
|
||||||
use url::Url;
|
use url::Url;
|
||||||
|
@ -19,9 +20,9 @@ use url::Url;
|
||||||
pub static CLIENT: Lazy<Client> = Lazy::new(Client::new);
|
pub static CLIENT: Lazy<Client> = Lazy::new(Client::new);
|
||||||
|
|
||||||
pub struct TestData {
|
pub struct TestData {
|
||||||
pub alpha: Instance,
|
pub alpha: FediwikiInstance,
|
||||||
pub beta: Instance,
|
pub beta: FediwikiInstance,
|
||||||
pub gamma: Instance,
|
pub gamma: FediwikiInstance,
|
||||||
}
|
}
|
||||||
|
|
||||||
impl TestData {
|
impl TestData {
|
||||||
|
@ -35,51 +36,56 @@ impl TestData {
|
||||||
.init();
|
.init();
|
||||||
});
|
});
|
||||||
|
|
||||||
// initialize postgres databases in parallel because its slow
|
let alpha_db_path = generate_db_path("alpha");
|
||||||
let (alpha_db_path, alpha_db_thread) = start_temporary_database("alpha");
|
let beta_db_path = generate_db_path("beta");
|
||||||
let (beta_db_path, beta_db_thread) = start_temporary_database("beta");
|
let gamma_db_path = generate_db_path("gamma");
|
||||||
let (gamma_db_path, gamma_db_thread) = start_temporary_database("gamma");
|
|
||||||
|
|
||||||
alpha_db_thread.join().unwrap();
|
// initialize postgres databases in parallel because its slow
|
||||||
beta_db_thread.join().unwrap();
|
for j in [
|
||||||
gamma_db_thread.join().unwrap();
|
FediwikiInstance::prepare_db(alpha_db_path.clone()),
|
||||||
|
FediwikiInstance::prepare_db(beta_db_path.clone()),
|
||||||
|
FediwikiInstance::prepare_db(gamma_db_path.clone()),
|
||||||
|
] {
|
||||||
|
j.join().unwrap();
|
||||||
|
}
|
||||||
|
|
||||||
Self {
|
Self {
|
||||||
alpha: Instance::start(alpha_db_path, 8131),
|
alpha: FediwikiInstance::start(alpha_db_path, 8131),
|
||||||
beta: Instance::start(beta_db_path, 8132),
|
beta: FediwikiInstance::start(beta_db_path, 8132),
|
||||||
gamma: Instance::start(gamma_db_path, 8133),
|
gamma: FediwikiInstance::start(gamma_db_path, 8133),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
pub fn stop(self) -> MyResult<()> {
|
pub fn stop(self) -> MyResult<()> {
|
||||||
self.alpha.stop();
|
for j in [self.alpha.stop(), self.beta.stop(), self.gamma.stop()] {
|
||||||
self.beta.stop();
|
j.join().unwrap();
|
||||||
self.gamma.stop();
|
}
|
||||||
Ok(())
|
Ok(())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn start_temporary_database(name: &'static str) -> (String, std::thread::JoinHandle<()>) {
|
fn generate_db_path(name: &'static str) -> String {
|
||||||
let db_path = format!("{}/target/test_db/{name}", current_dir().unwrap().display());
|
format!("{}/target/test_db/{name}", current_dir().unwrap().display())
|
||||||
let db_path_ = db_path.clone();
|
}
|
||||||
let db_thread = std::thread::spawn(move || {
|
|
||||||
|
pub struct FediwikiInstance {
|
||||||
|
pub hostname: String,
|
||||||
|
db_path: String,
|
||||||
|
db_handle: JoinHandle<()>,
|
||||||
|
}
|
||||||
|
|
||||||
|
impl FediwikiInstance {
|
||||||
|
fn prepare_db(db_path: String) -> std::thread::JoinHandle<()> {
|
||||||
|
spawn(move || {
|
||||||
Command::new("./tests/scripts/start_dev_db.sh")
|
Command::new("./tests/scripts/start_dev_db.sh")
|
||||||
.arg(&db_path_)
|
.arg(&db_path)
|
||||||
.stdout(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
.stderr(Stdio::null())
|
.stderr(Stdio::null())
|
||||||
.output()
|
.output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
});
|
})
|
||||||
(db_path, db_thread)
|
}
|
||||||
}
|
|
||||||
|
|
||||||
pub struct Instance {
|
|
||||||
db_path: String,
|
|
||||||
pub hostname: String,
|
|
||||||
handle: JoinHandle<()>,
|
|
||||||
}
|
|
||||||
|
|
||||||
impl Instance {
|
|
||||||
fn start(db_path: String, port: i32) -> Self {
|
fn start(db_path: String, port: i32) -> Self {
|
||||||
let db_url = format!("postgresql://lemmy:password@/lemmy?host={db_path}");
|
let db_url = format!("postgresql://lemmy:password@/lemmy?host={db_path}");
|
||||||
let hostname = format!("localhost:{port}");
|
let hostname = format!("localhost:{port}");
|
||||||
|
@ -90,18 +96,20 @@ impl Instance {
|
||||||
Self {
|
Self {
|
||||||
db_path,
|
db_path,
|
||||||
hostname,
|
hostname,
|
||||||
handle,
|
db_handle: handle,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn stop(self) {
|
fn stop(self) -> std::thread::JoinHandle<()> {
|
||||||
self.handle.abort();
|
self.db_handle.abort();
|
||||||
|
spawn(move || {
|
||||||
Command::new("./tests/scripts/stop_dev_db.sh")
|
Command::new("./tests/scripts/stop_dev_db.sh")
|
||||||
.arg(&self.db_path)
|
.arg(&self.db_path)
|
||||||
.stdout(Stdio::null())
|
.stdout(Stdio::null())
|
||||||
.stderr(Stdio::null())
|
.stderr(Stdio::null())
|
||||||
.output()
|
.output()
|
||||||
.unwrap();
|
.unwrap();
|
||||||
|
})
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -4,15 +4,17 @@ set -e
|
||||||
export PGHOST=$1
|
export PGHOST=$1
|
||||||
export PGDATA="$1/dev_pgdata"
|
export PGDATA="$1/dev_pgdata"
|
||||||
|
|
||||||
# If cluster exists, stop the server and delete the cluster
|
# If cluster exists, stop the server
|
||||||
if [ -d $PGDATA ]
|
if [ -d $PGDATA ]
|
||||||
then
|
then
|
||||||
# Prevent `stop` from failing if server already stopped
|
# Prevent `stop` from failing if server already stopped
|
||||||
pg_ctl restart > /dev/null
|
pg_ctl restart > /dev/null
|
||||||
pg_ctl stop
|
pg_ctl stop
|
||||||
rm -rf $PGDATA
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# Remove any leftover data from revious run
|
||||||
|
rm -rf $PGDATA
|
||||||
|
|
||||||
# Create cluster
|
# Create cluster
|
||||||
initdb --username=postgres --auth=trust --no-instructions
|
initdb --username=postgres --auth=trust --no-instructions
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue