From abe3e28a498e0fae4fdfb3d7ea26936372d7205e Mon Sep 17 00:00:00 2001 From: Agent Date: Thu, 2 Apr 2026 09:12:17 +0000 Subject: [PATCH] fix: write actual mock port to file for smoke test --- .woodpecker/smoke-init.yml | 11 +++++++---- tests/mock-forgejo.py | 7 ++++--- 2 files changed, 11 insertions(+), 7 deletions(-) diff --git a/.woodpecker/smoke-init.yml b/.woodpecker/smoke-init.yml index b15a6d2..290b75d 100644 --- a/.woodpecker/smoke-init.yml +++ b/.woodpecker/smoke-init.yml @@ -32,7 +32,10 @@ steps: image: python:3-alpine commands: - apk add --no-cache bash curl jq git coreutils - - MOCK_FORGE_PORT=3001 python3 tests/mock-forgejo.py > /tmp/mock.log 2>&1 & - # Wait for mock to be ready (might be on a different port if 3001 is in use) - - for i in $(seq 1 30); do curl -sf http://localhost:$MOCK_FORGE_PORT/api/v1/version >/dev/null 2>&1 && break || sleep 1; done - - SMOKE_FORGE_URL=http://localhost:$MOCK_FORGE_PORT FORGE_URL=http://localhost:$MOCK_FORGE_PORT bash tests/smoke-init.sh + - MOCK_FORGE_PORT=3001 MOCK_FORGE_PORT_FILE=/tmp/mock-port python3 tests/mock-forgejo.py > /tmp/mock.log 2>&1 & + - MOCK_PID=$! + # Wait for mock to be ready + - for i in $(seq 1 30); do [ -f /tmp/mock-port ] && break || sleep 1; done + - MOCK_PORT=$(cat /tmp/mock-port 2>/dev/null || echo "3001") + - for i in $(seq 1 30); do curl -sf http://localhost:$MOCK_PORT/api/v1/version >/dev/null 2>&1 && break || sleep 1; done + - SMOKE_FORGE_URL=http://localhost:$MOCK_PORT FORGE_URL=http://localhost:$MOCK_PORT bash tests/smoke-init.sh diff --git a/tests/mock-forgejo.py b/tests/mock-forgejo.py index fa848a8..d4478c5 100755 --- a/tests/mock-forgejo.py +++ b/tests/mock-forgejo.py @@ -719,9 +719,10 @@ def main(): base_port = int(os.environ.get("MOCK_FORGE_PORT", 3000)) port = find_free_port(base_port) - # If we found a different port, update the environment variable - if port != base_port: - os.environ["MOCK_FORGE_PORT"] = str(port) + # Write actual port to a file for the test script to read + port_file = os.environ.get("MOCK_FORGE_PORT_FILE", "/tmp/mock-forgejo-port") + with open(port_file, "w") as f: + f.write(str(port)) server = ThreadingHTTPServer(("0.0.0.0", port), ForgejoHandler)