diff --git a/Makefile b/Makefile index c3e3b77..7a8d7ff 100644 --- a/Makefile +++ b/Makefile @@ -2,7 +2,7 @@ test: make test-api make test-ui test-api: - docker compose -f docker/docker-compose.yaml run actix-api bash -c "cd app/actix-api && cargo test -- --nocapture" + docker compose -f docker/docker-compose.yaml run actix-api bash -c "cd app/actix-api && cargo test -- --nocapture --test-threads=1" test-ui: docker compose -f docker/docker-compose.yaml run yew-ui bash -c "cd app/yew-ui && cargo test" up: diff --git a/actix-api/tests/common.rs b/actix-api/tests/common.rs index bf4d305..26a2544 100644 --- a/actix-api/tests/common.rs +++ b/actix-api/tests/common.rs @@ -1,17 +1,26 @@ use std::process::Command; -pub fn dbmate_up(url: &str) { - log::info!("dbmate up DATABASE_URL: {}", url); - let do_steps = || -> bool { - Command::new("sh") - .arg("-c") - .arg("dbmate up") +pub fn dbmate_rebuild(url: &str) { + let do_steps = || -> anyhow::Result<()> { + Command::new("dbmate") + .arg("drop") + .env("DATABASE_URL", &url) + .status() + .expect("failed to execute process"); + Command::new("dbmate") + .arg("up") + .env("DATABASE_URL", &url) + .status() + .expect("failed to execute process"); + Command::new("dbmate") + .arg("wait") .env("DATABASE_URL", url) .status() - .expect("failed to execute process") - .success() + .expect("failed to execute process"); + Ok(()) }; - if !do_steps() { - panic!("Failed to perform dbmate up operation"); + if let Err(err) = do_steps() { + println!("Failed to perform db operation {}", err.to_string()); + dbmate_rebuild(url); } } diff --git a/actix-api/tests/server.rs b/actix-api/tests/server.rs index 9c990d3..08909db 100644 --- a/actix-api/tests/server.rs +++ b/actix-api/tests/server.rs @@ -11,7 +11,7 @@ use types::HelloResponse; async fn test_login() { let db_url = std::env::var("PG_URL").unwrap(); println!("DB_URL: {}", db_url); - common::dbmate_up(&db_url); + common::dbmate_rebuild(&db_url); let mut app = test::init_service(get_app()).await; let req = test::TestRequest::get().uri("/hello/dario").to_request(); let resp = test::call_service(&mut app, req).await;