fix: add PostgreSQL startup wait loop before test database setup
- PostgreSQL container takes time to fully initialize after docker compose up - Previous fix didn't account for container startup time - Add explicit wait loop (30 second timeout) for PostgreSQL service to be ready - Only create test database AFTER PostgreSQL itself responds to connections - Prevents 'database system is starting up' errors - More robust and handles slower container startup scenarios
This commit is contained in:
+17
-4
@@ -53,7 +53,23 @@ log_step "Resetting PostgreSQL..."
|
||||
docker compose down -v postgres > /dev/null 2>&1
|
||||
docker compose up postgres -d > /dev/null 2>&1
|
||||
log_success "PostgreSQL reset complete"
|
||||
sleep 3
|
||||
|
||||
# --- 3a. Wait for PostgreSQL to be ready ---
|
||||
log_step "Waiting for PostgreSQL to initialize..."
|
||||
MAX_STARTUP_ATTEMPTS=30
|
||||
STARTUP_ATTEMPT=0
|
||||
while [ $STARTUP_ATTEMPT -lt $MAX_STARTUP_ATTEMPTS ]; do
|
||||
if docker exec postgres psql -U myuser -d mydb -c "SELECT 1;" > /dev/null 2>&1; then
|
||||
log_success "PostgreSQL is ready"
|
||||
break
|
||||
fi
|
||||
STARTUP_ATTEMPT=$((STARTUP_ATTEMPT+1))
|
||||
sleep 1
|
||||
done
|
||||
if [ $STARTUP_ATTEMPT -eq $MAX_STARTUP_ATTEMPTS ]; then
|
||||
log_error "PostgreSQL failed to start after $MAX_STARTUP_ATTEMPTS attempts"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# --- 3b. Create Test Database ---
|
||||
log_step "Setting up test database (crussell_test)..."
|
||||
@@ -64,7 +80,6 @@ sleep 1
|
||||
log_step "Seeding test database schema..."
|
||||
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
|
||||
@@ -408,8 +423,6 @@ echo "${C_GREEN}✅ Created $count_future/30 Bookings (Future)${C_RESET}"
|
||||
echo "${C_GREEN}✅ Created $count_past/8 Bookings (Past)${C_RESET}"
|
||||
echo "${C_GREEN}✅ Created $TOTAL/45 Bookings (Total)${C_RESET}"
|
||||
|
||||
# 5. Confirm Random Half of Upcoming Bookings
|
||||
echo -e "\n${C_BLUE}🔒 Confirming Random Upcoming Bookings...${C_RESET}"
|
||||
# 5. Confirm Random Half of Upcoming Bookings
|
||||
echo -e "\n${C_BLUE}🔒 Confirming Random Upcoming Bookings...${C_RESET}"
|
||||
confirmed_count=0
|
||||
|
||||
Reference in New Issue
Block a user