Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit concurrent tests and fix dbmate function #28

Merged
merged 1 commit into from
Nov 25, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading