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
This commit is contained in:
@@ -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",
|
||||
|
||||
+20
-4
@@ -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)..."
|
||||
|
||||
Reference in New Issue
Block a user