test(wake): #918 de-flake T7 ack-no-network-block (sub-second timing) (#919)
All checks were successful
ci/woodpecker/push/publish Pipeline was successful
ci/woodpecker/push/ci Pipeline was successful

Co-authored-by: jason.woltje <jason@diversecanvas.com>
Co-committed-by: jason.woltje <jason@diversecanvas.com>
This commit was merged in pull request #919.
This commit is contained in:
2026-07-26 06:46:28 +00:00
committed by Mos
parent e2ec927b1c
commit c585ac3326

View File

@@ -247,11 +247,19 @@ EOF
done done
# Background sync deliberately SLOW: proves the ack does not wait for it. # Background sync deliberately SLOW: proves the ack does not wait for it.
export WAKE_ACK_SYNC_CMD="sleep 3; touch '$WAKE_STATE_HOME/SYNC_DONE'" export WAKE_ACK_SYNC_CMD="sleep 3; touch '$WAKE_STATE_HOME/SYNC_DONE'"
start="$(date +%s)" # Sub-second timing (#918): `date +%s` is SECOND-granularity, so a
# legitimately fast (sub-second) ack that straddles a wall-clock second
# boundary can misreport elapsed=2s and flake under CI load (observed on
# Woodpecker pipeline 2057; 20/20 passes locally elsewhere). Use
# `date +%s.%N` and compare in milliseconds via awk (bash `[ ]` can't do
# float/ms math) against a threshold comfortably below the 3s background
# sync — proving the ack did NOT wait on it — while tolerating a
# legitimate sub-second-to-~1s ack across a boundary.
start="$(date +%s.%N)"
out="$(PATH="$bin:$PATH" "$ACK" consumed --upto 1 --wake-id WID-1)" out="$(PATH="$bin:$PATH" "$ACK" consumed --upto 1 --wake-id WID-1)"
end="$(date +%s)" end="$(date +%s.%N)"
elapsed=$((end - start)) elapsed_ms="$(awk -v s="$start" -v e="$end" 'BEGIN { printf "%d", (e - s) * 1000 }')"
[ "$elapsed" -lt 2 ] || fail_msg "T7: ack path blocked ${elapsed}s — must return without waiting on the background sync" [ "$elapsed_ms" -lt 1500 ] || fail_msg "T7: ack path blocked ${elapsed_ms}ms — must return without waiting on the background sync"
echo "$out" | grep -q 'CONSUMED 1' || fail_msg "T7: CONSUMED not reported [$out]" echo "$out" | grep -q 'CONSUMED 1' || fail_msg "T7: CONSUMED not reported [$out]"
# Local write is durable IMMEDIATELY (no network needed to record the ack). # Local write is durable IMMEDIATELY (no network needed to record the ack).
STATE_DIR="$WAKE_STATE_HOME/default" STATE_DIR="$WAKE_STATE_HOME/default"