mirror of
https://github.com/nomadkaraoke/karaoke-gen.git
synced 2026-11-20 13:07:57 +09:00
fix: prevent test hanging from emulator prompts, zombies, port conflicts (#448)
## Summary - Add `--quiet` flag to `gcloud beta emulators firestore start` to prevent interactive prompts that hang CI/agent sessions - Fix `stop-emulators.sh` to kill Java child processes (`pkill -P`) with port-based fallback for orphans on port 8080 - Generate unique Playwright dev server port per worktree (3100-3199 hash range) to prevent cross-worktree conflicts ## Test plan - [ ] `./scripts/start-emulators.sh` starts without interactive prompts - [ ] `./scripts/stop-emulators.sh` kills Java emulator child processes (no orphans on port 8080) - [ ] Playwright config generates different ports for different worktree directories - [ ] `E2E_PORT` env var still overrides the default port <!-- @coderabbitai ignore --> 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-authored-by: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
1 parent
3e81bbe9a8
commit
a38096e8cc
3 files changed
+24
-17
No files matched your search
@@ -18,9 +18,18 @@ if (fs.existsSync(envLocalPath)) {
|
||||
}
|
||||
}
|
||||
|
||||
// Configurable port for dev server (default: 3000)
|
||||
// Use E2E_PORT env var to change, e.g.: E2E_PORT=3001 npx playwright test
|
||||
const PORT = process.env.E2E_PORT || '3000';
|
||||
// Generate a stable port per worktree directory to avoid cross-worktree conflicts.
|
||||
// Each worktree gets a unique port in the 3100-3199 range based on a hash of __dirname.
|
||||
// Override with E2E_PORT env var, e.g.: E2E_PORT=3001 npx playwright test
|
||||
const DEFAULT_PORT = (() => {
|
||||
const dir = __dirname;
|
||||
let hash = 0;
|
||||
for (let i = 0; i < dir.length; i++) {
|
||||
hash = ((hash << 5) - hash + dir.charCodeAt(i)) | 0;
|
||||
}
|
||||
return 3100 + (Math.abs(hash) % 100); // 3100-3199
|
||||
})();
|
||||
const PORT = process.env.E2E_PORT || String(DEFAULT_PORT);
|
||||
// Use 127.0.0.1 instead of localhost to avoid IPv6 resolution issues on macOS.
|
||||
// localhost resolves to ::1 (IPv6) first, but Next.js dev server may not accept
|
||||
// IPv6 connections, causing Playwright's webServer health check to hang.
|
||||
|
||||
@@ -21,6 +21,7 @@ else
|
||||
echo "📦 Starting Firestore emulator on port 8080..."
|
||||
gcloud beta emulators firestore start \
|
||||
--host-port=127.0.0.1:8080 \
|
||||
--quiet \
|
||||
> "$EMULATOR_LOG_DIR/firestore.log" 2>&1 &
|
||||
|
||||
FIRESTORE_PID=$!
|
||||
|
||||
+11
-14
@@ -16,23 +16,20 @@ if [ -f "$EMULATOR_LOG_DIR/firestore.pid" ]; then
|
||||
FIRESTORE_PID=$(cat "$EMULATOR_LOG_DIR/firestore.pid")
|
||||
if ps -p $FIRESTORE_PID > /dev/null 2>&1; then
|
||||
echo "📦 Stopping Firestore emulator (PID: $FIRESTORE_PID)..."
|
||||
# Kill the process and its children (Java emulator subprocess)
|
||||
pkill -P $FIRESTORE_PID 2>/dev/null || true
|
||||
kill $FIRESTORE_PID 2>/dev/null || true
|
||||
rm "$EMULATOR_LOG_DIR/firestore.pid"
|
||||
echo " ✅ Firestore emulator stopped"
|
||||
else
|
||||
echo "⚠️ Firestore emulator not running"
|
||||
rm "$EMULATOR_LOG_DIR/firestore.pid"
|
||||
fi
|
||||
rm -f "$EMULATOR_LOG_DIR/firestore.pid"
|
||||
fi
|
||||
# Always clean up by port as a fallback (catches orphaned Java processes)
|
||||
REMAINING=$(lsof -ti:8080 2>/dev/null || true)
|
||||
if [ -n "$REMAINING" ]; then
|
||||
echo "📦 Cleaning up remaining processes on port 8080..."
|
||||
kill $REMAINING 2>/dev/null || true
|
||||
echo " ✅ Firestore emulator stopped"
|
||||
else
|
||||
# Try to kill by port if PID file doesn't exist
|
||||
FIRESTORE_PID=$(lsof -ti:8080 2>/dev/null || true)
|
||||
if [ ! -z "$FIRESTORE_PID" ]; then
|
||||
echo "📦 Stopping Firestore emulator on port 8080 (PID: $FIRESTORE_PID)..."
|
||||
kill $FIRESTORE_PID 2>/dev/null || true
|
||||
echo " ✅ Firestore emulator stopped"
|
||||
else
|
||||
echo "⚠️ Firestore emulator not running"
|
||||
fi
|
||||
echo "⚠️ Firestore emulator not running"
|
||||
fi
|
||||
|
||||
# Stop GCS emulator
|
||||
|
||||
Reference in new issue
Block a user