From 03ee3ee5d5c8a24a042a70edffc1d680d8af8337 Mon Sep 17 00:00:00 2001 From: Djeex Date: Wed, 26 Aug 2026 15:55:39 +0200 Subject: [PATCH] Fix flaky unit test on merge-triggered CI runs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - entrypoint.sh: bound the target connectivity check with -w 2 (nc -z had no timeout at all, the only unbounded step in the startup path) - tests/entrypoint.bats: widen wait_for_log's budget from 5s to 10s Merge-triggered runs land on a colder runner (Docker cache evicted by other repos' scheduled jobs since the PR was last tested) than PR-check runs, and the first backgrounded entrypoint.sh in the suite was occasionally landing just past the old 5s window — always passed on rerun once warm. --- entrypoint.sh | 2 +- tests/entrypoint.bats | 6 +++++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/entrypoint.sh b/entrypoint.sh index 4c3923d..0d68ff9 100644 --- a/entrypoint.sh +++ b/entrypoint.sh @@ -145,7 +145,7 @@ fi log "[~] Testing connection to target..." # Test if we can reach the target before starting socat -if ! nc -z "$TARGET_HOST" "$TARGET_PORT" 2>/dev/null; then +if ! nc -z -w 2 "$TARGET_HOST" "$TARGET_PORT" 2>/dev/null; then log "[!] Cannot connect to $TARGET_HOST:$TARGET_PORT - socat will retry automatically" else log "[✓] Connection to $TARGET_HOST:$TARGET_PORT is working" diff --git a/tests/entrypoint.bats b/tests/entrypoint.bats index 2146d76..bf09219 100644 --- a/tests/entrypoint.bats +++ b/tests/entrypoint.bats @@ -58,7 +58,11 @@ socat_pid() { wait_for_log() { pattern="$1" tries=0 - while [ "$tries" -lt 20 ]; do + # 40 * 0.25s = 10s — merge-triggered runs can land on a cold runner + # (evicted Docker cache, first container start), pushing the very first + # backgrounded entrypoint.sh past a tighter budget even though nothing's + # actually wrong; a rerun on a warm runner always passes. + while [ "$tries" -lt 40 ]; do grep -qE "$pattern" "$LOG" 2>/dev/null && return 0 tries=$((tries + 1)) sleep 0.25