From ce96f5abf4ca280cbb9d620feb8865d40f2e2e2a Mon Sep 17 00:00:00 2001 From: Dan Notestein Date: Mon, 29 Dec 2025 02:31:58 -0500 Subject: [PATCH] Add TCP port wait to benchmark job template to fix service race condition - Add before_script that waits for app service using nc -z - Add SERVICE_WAIT_TIMEOUT variable (default: 120s) - Progress logging every 2 seconds - Prevents flaky CI failures due to DNS/service startup timing --- templates/test_jobs.gitlab-ci.yml | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/templates/test_jobs.gitlab-ci.yml b/templates/test_jobs.gitlab-ci.yml index 3a24d9c..f2f471e 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 -- GitLab