diff --git a/templates/test_jobs.gitlab-ci.yml b/templates/test_jobs.gitlab-ci.yml index 3a24d9ce6655976903c2fa5761c35942620e70a7..f2f471e7785003a054dc1e2f3349b70712edf92e 100644 --- a/templates/test_jobs.gitlab-ci.yml +++ b/templates/test_jobs.gitlab-ci.yml @@ -131,8 +131,27 @@ include: variables: HAF_COMMIT: $HAF_COMMIT # dotenv artifacts can be passed to service as long as they appear in section variables FF_NETWORK_PER_BUILD: 1 + # Maximum time to wait for service to be ready (seconds) + SERVICE_WAIT_TIMEOUT: 120 services: - !reference [.haf_app_pattern_tests_template, services] + before_script: + # Wait for the app service to be ready before running tests + # This eliminates race conditions where DNS or the service isn't ready yet + - | + echo "Waiting for app service on port ${HAF_APP_PORT}..." + start_time=$(date +%s) + while ! nc -z app ${HAF_APP_PORT} 2>/dev/null; do + current_time=$(date +%s) + elapsed=$((current_time - start_time)) + if [ $elapsed -ge ${SERVICE_WAIT_TIMEOUT} ]; then + echo "ERROR: Timeout waiting for app:${HAF_APP_PORT} after ${SERVICE_WAIT_TIMEOUT}s" + exit 1 + fi + echo "Waiting for app:${HAF_APP_PORT}... (${elapsed}s elapsed)" + sleep 2 + done + echo "Service app:${HAF_APP_PORT} is ready" .tox_test_job: extends: .job-defaults