fix fragile tests
CI Feature / Load example-gitea-env.conf to pipeline env (push) Successful in 19s
acc-tests Cucumber test report
CI Feature / Cucumber tests (push) Failing after 2m11s
unit-tests Bats test report
CI Feature / Bats tests (push) Failing after 7m10s
CI Feature / Report Summary (push) Successful in 5s

This commit is contained in:
moilanik
2026-06-20 13:34:03 +03:00
parent 0a9a9c88f1
commit a039e6637e
5 changed files with 35 additions and 15 deletions
+19 -3
View File
@@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -euo pipefail
MOCK_PORT=18080
MOCK_PORT=""
MOCK_PID=""
MOCK_REQUEST_FILE=""
MOCK_RESPONSE_CODE=201
@@ -9,11 +9,17 @@ MOCK_STATE_FILE="/tmp/mock_api_state"
MOCK_SEQUENCE_FILE=""
MOCK_CONFIG_FILE=""
_free_port() {
python3 -c "import socket; s=socket.socket(); s.bind(('',0)); print(s.getsockname()[1]); s.close()"
}
_kill_port() {
local pids
pids=$(lsof -ti ":$MOCK_PORT" 2>/dev/null) || true
[ -n "$pids" ] && kill -9 $pids 2>/dev/null || true
[ -n "$pids" ] && kill $pids 2>/dev/null || true
sleep 0.5
pids=$(lsof -ti ":$MOCK_PORT" 2>/dev/null) || true
[ -n "$pids" ] && kill -9 $pids 2>/dev/null || true
}
_wait_port_free() {
@@ -26,10 +32,14 @@ _wait_port_free() {
_wait_port_ready() {
local i=0
while ! lsof -ti ":$MOCK_PORT" >/dev/null 2>&1 && [ $i -lt 5 ]; do
while [ $i -lt 50 ]; do
if nc -z localhost "$MOCK_PORT" 2>/dev/null; then
return 0
fi
sleep 0.2
i=$((i + 1))
done
return 1
}
mock_set_sequence() {
@@ -43,6 +53,12 @@ mock_clear_sequence() {
}
mock_start() {
MOCK_PORT=$(_free_port)
export MOCK_PORT
MOCK_URL="http://localhost:${MOCK_PORT}"
export SERVER_URL="$MOCK_URL"
export GITEA_API_URL="$MOCK_URL"
MOCK_RESPONSE_CODE="${MOCK_RESPONSE_CODE:-201}"
MOCK_REQUEST_FILE=$(mktemp)
echo "$MOCK_REQUEST_FILE" > "$MOCK_STATE_FILE"