Skip to content

Commit 8456fac

Browse files
test(e2e): pin the stability-window reset and keep the fan-out test portable
The readiness gate resets its stability window when a list read fails, and nothing held that: the existing "transient list error" case fails on the first read, when there is no window to invalidate, so removing the reset left the suite green. The new case breaks a read mid-window, where a gate that kept counting through the gap would accept a release set it never observed stable across it. The parallel fan-out contract asked make for --output-sync, which arrived in GNU Make 4.0 while macOS still ships 3.81 -- so on a contributor's machine the suite died on an unknown option instead of reporting the contract. Guarded by version, with the reason in place. CI runs 4.x, so the contract is still enforced where it gates a merge. Signed-off-by: Myasnikov Daniil <[email protected]> Assisted-By: LLM
1 parent b30c7ef commit 8456fac

2 files changed

Lines changed: 47 additions & 0 deletions

File tree

‎hack/helmrelease-readiness.bats‎

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,43 @@ helmrelease_snapshot() {
142142
fi
143143
}
144144

145+
@test "a failed read invalidates a stability window already in progress" {
146+
# The list-error branch resets stable_fingerprint and stable_since, and the
147+
# "transient list error" case above does not pin that: its read fails on the
148+
# first call, when there is no window to invalidate. Reverting the reset left
149+
# the suite green. Here the failure lands mid-window, so a gate that kept
150+
# counting through it returns at the original start plus quiet_seconds
151+
# instead of restarting the clock -- which would accept a set that was never
152+
# observed stable across the gap.
153+
. hack/e2e-wait-helmreleases.sh
154+
clock=$(mktemp)
155+
calls=$(mktemp)
156+
printf '0\n' > "$clock"
157+
date() { sed -n '1p' "$clock"; }
158+
sleep() {
159+
now=$(sed -n '1p' "$clock")
160+
printf '%s\n' "$(( now + $1 ))" > "$clock"
161+
}
162+
kubectl() {
163+
count=$(wc -l < "$calls")
164+
printf 'call\n' >> "$calls"
165+
# Ready on the first read, unreadable on the second, Ready again after:
166+
# the window opens at t=0, is broken at t=2, and may only complete a
167+
# full quiet period measured from the read that reopened it.
168+
if [ "$count" -eq 1 ]; then
169+
echo 'temporary apiserver error' >&2
170+
return 1
171+
fi
172+
helmrelease_snapshot 11
173+
}
174+
175+
cozy_wait_all_helmreleases_ready 60 11 6 2 >/dev/null 2>&1
176+
if [ "$(sed -n '1p' "$clock")" -lt 10 ]; then
177+
echo "the gate counted the broken read as part of the stability window" >&2
178+
exit 1
179+
fi
180+
}
181+
145182
@test "a read slower than the poll interval is charged against the deadline" {
146183
# `now` is sampled after the list read, not before it. Sampled before, a read
147184
# that costs more than the poll interval is priced at zero and the loop buys

‎hack/unit-test-parallelism.bats‎

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,16 @@
22
# Contract for the bounded parallel unit-test fan-out used by PR CI.
33

44
@test "every non-E2E BATS file is an independent Make prerequisite" {
5+
# --output-sync arrived in GNU Make 4.0, and macOS still ships 3.81, where
6+
# this invocation dies on an unknown option rather than telling the reader
7+
# why. CI is on 4.x, so the contract is still enforced where it gates a
8+
# merge; skipping here keeps the suite runnable on a contributor's machine
9+
# instead of failing for a reason that has nothing to do with the contract.
10+
make_major=$(make --version 2>/dev/null | sed -n '1s/^GNU Make \([0-9][0-9]*\).*/\1/p')
11+
if [ -z "$make_major" ] || [ "$make_major" -lt 4 ]; then
12+
echo "skipped: this make has no --output-sync (needs GNU Make >= 4.0)" >&2
13+
return 0
14+
fi
515
expected=$(find hack -maxdepth 1 -type f -name '*.bats' ! -name 'e2e-*.bats' | wc -l)
616
output=$(make -n -j4 --output-sync=target bats-unit-tests)
717
# The COZYTEST_TRACE prefix is part of the pattern on purpose: the switch is

0 commit comments

Comments
 (0)