Skip to content

Commit 98af9fb

Browse files
sarroutbiclaude
andcommitted
Fix Mockoon port conflict in CI registrar tests
The CI job for mockoon-registrar-tests was failing because both the GitHub Actions mockoon/cli-action and the test script were trying to start Mockoon on port 3001, causing a "Port 3001 is already in use" error. Changes: - Enhanced port detection logic in tests/mockoon_registrar_tests.sh to use multiple methods (lsof, netstat, ss, and curl) for detecting if port 3001 is already in use - Improved cleanup logic to properly terminate Mockoon processes using multiple methods (kill by PID, lsof, pkill by process name) - Made the script more robust in CI environments where lsof might not be available or behave differently The test script now properly detects when Mockoon is already running (started by the GitHub Actions workflow) and skips starting a duplicate instance, avoiding the port conflict. Co-Authored-By: Claude <[email protected]> Signed-off-by: Sergio Arroutbi <[email protected]>
1 parent a58bc9a commit 98af9fb

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

tests/mockoon_registrar_tests.sh

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,19 @@ fi
3131
mkdir -p /var/lib/keylime
3232

3333
# Check if Mockoon is already running on port 3001 (e.g., in CI)
34+
# Try multiple methods to detect if port 3001 is in use
35+
PORT_IN_USE=false
3436
if lsof -i :3001 > /dev/null 2>&1; then
37+
PORT_IN_USE=true
38+
elif netstat -ln 2>/dev/null | grep -q ':3001 '; then
39+
PORT_IN_USE=true
40+
elif ss -ln 2>/dev/null | grep -q ':3001 '; then
41+
PORT_IN_USE=true
42+
elif curl -s --connect-timeout 2 http://localhost:3001 > /dev/null 2>&1; then
43+
PORT_IN_USE=true
44+
fi
45+
46+
if $PORT_IN_USE; then
3547
echo "-------- Mockoon already running on port 3001 (likely in CI)"
3648
MOCKOON_PID=""
3749
else
@@ -84,9 +96,21 @@ if [ -n "$MOCKOON_PID" ]; then
8496
wait $MOCKOON_PID 2>/dev/null || true
8597

8698
# Check if port 3001 is still in use and force cleanup if needed
99+
PORT_STILL_IN_USE=false
87100
if lsof -i :3001 > /dev/null 2>&1; then
101+
PORT_STILL_IN_USE=true
102+
elif netstat -ln 2>/dev/null | grep -q ':3001 '; then
103+
PORT_STILL_IN_USE=true
104+
elif ss -ln 2>/dev/null | grep -q ':3001 '; then
105+
PORT_STILL_IN_USE=true
106+
fi
107+
108+
if $PORT_STILL_IN_USE; then
88109
echo "Warning: Port 3001 still in use, forcing cleanup"
89110
lsof -ti :3001 | xargs kill -9 2>/dev/null || true
111+
# Additional cleanup methods
112+
pkill -f "mockoon-cli.*3001" 2>/dev/null || true
113+
pkill -f "node.*mockoon.*3001" 2>/dev/null || true
90114
fi
91115
else
92116
echo "-------- Mockoon was already running (CI), not stopping it"

0 commit comments

Comments
 (0)