From fb0a7fa59b6e4422b9030a3121b57e685cf26e80 Mon Sep 17 00:00:00 2001 From: Stephen Adamson Date: Sun, 22 Feb 2026 00:20:28 +0000 Subject: [PATCH] fix: test database setup and scheduling test build error - Add explicit verification loop in local-dev-2.sh to wait for crussell_test database to be ready before running tests (prevents race condition) - Remove unused 'handler' variable declaration in scheduling_test.go that was breaking the build - Tests now properly execute without immediate 'database does not exist' errors - Real test failures are now visible instead of being masked by setup issues --- .../handlers/scheduling/scheduling_test.go | 2 +- local-dev-2.sh | 24 +++++++++++++++---- 2 files changed, 21 insertions(+), 5 deletions(-) diff --git a/backend/handlers/scheduling/scheduling_test.go b/backend/handlers/scheduling/scheduling_test.go index 3a2a04e..99cf07e 100644 --- a/backend/handlers/scheduling/scheduling_test.go +++ b/backend/handlers/scheduling/scheduling_test.go @@ -300,7 +300,7 @@ func TestScheduling_CreateExceptionalGroup_NonAdmin(t *testing.T) { defer cleanup() userToken := jwt.GenerateUserToken("user-123") - handler := http.HandlerFunc(CreateExceptionalGroup) + newGroup := ExceptionalGroup{ Name: "Summer Hours", diff --git a/local-dev-2.sh b/local-dev-2.sh index 7e35871..fea9d9a 100755 --- a/local-dev-2.sh +++ b/local-dev-2.sh @@ -57,14 +57,30 @@ sleep 3 # --- 3b. Create Test Database --- log_step "Setting up test database (crussell_test)..." -docker exec postgres psql -U myuser -d mydb -c "CREATE DATABASE crussell_test;" 2>/dev/null || true -log_success "Test database ready" +docker exec postgres psql -U myuser -d mydb -c "CREATE DATABASE crussell_test;" 2>&1 || log_info "Test database may already exist" sleep 1 # --- 3c. Seed Test Database Schema --- log_step "Seeding test database schema..." -docker exec -i postgres psql -U myuser -d crussell_test < init-scripts/init-script.sql > /dev/null 2>&1 || true -log_success "Test database schema ready" +docker exec -i postgres psql -U myuser -d crussell_test < init-scripts/init-script.sql 2>&1 | head -5 || true +log_success "Test database schema seeded" + +# --- 3d. Verify test database is ready --- +log_step "Verifying test database readiness..." +MAX_ATTEMPTS=10 +ATTEMPT=0 +while [ $ATTEMPT -lt $MAX_ATTEMPTS ]; do + if docker exec postgres psql -U myuser -d crussell_test -c "SELECT 1;" > /dev/null 2>&1; then + log_success "Test database ready" + break + fi + ATTEMPT=$((ATTEMPT+1)) + sleep 1 +done +if [ $ATTEMPT -eq $MAX_ATTEMPTS ]; then + log_error "Test database failed to initialize after $MAX_ATTEMPTS attempts" + exit 1 +fi # --- 3d. Rustfs (don't wipe data, just restart) --- log_step "Restarting Rustfs (S3-compatible storage)..."