Skip to content

Commit

Permalink
Limit concurrent tests and fix dbmate function (#28)
Browse files Browse the repository at this point in the history
  • Loading branch information
darioalessandro committed Nov 25, 2023
1 parent 93bb8dd commit 135e493
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
29 changes: 19 additions & 10 deletions actix-api/tests/common.rs
Original file line number Diff line number Diff line change
@@ -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);
}
}
2 changes: 1 addition & 1 deletion actix-api/tests/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down

0 comments on commit 135e493

Please sign in to comment.