Files
seaweedfs/seaweed-block/.github/scripts/record-go-test-test.sh
T
pingqiuandClaude Opus 5.5 7cb62f3b71 ci: the stderr fallback and a missing recorder have their own controls
The dead-recorder twins wrote a large stdout but one short stderr line,
so removing only the stderr fallback still passed. A fake Go that writes
10,000 stderr lines now runs with a recorder that dies after 100 bytes,
and with no recorder at all (no such interpreter); each keeps Go's own
exit 0 and 7, and dropping the stderr fallback turns the suite red.

The sampler stop test's wait for its stand-in is bounded (10 s) and
fails at once if the stand-in exits before it is ready.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
2026-12-02 00:42:45 -08:00

76 lines
3.8 KiB
Bash

#!/usr/bin/env bash
set -euo pipefail
here=$(cd "$(dirname "$0")" && pwd)
root=$(mktemp -d)
trap 'rm -rf "$root"' EXIT
mkdir -p "$root/bin"
cat >"$root/bin/go" <<'EOF'
#!/usr/bin/env bash
set -e
test "$1" = test && test "$2" = -json || exit 99
printf '%s\n' '{"Time":"2026-12-02T00:00:01Z","Action":"run","Test":"TestX"}'
printf '%s\n' '{"Time":"2026-12-02T00:00:02Z","Action":"output","Test":"TestX","Output":"fixture output\n"}'
printf '%s\n' '{"Time":"2026-12-02T00:00:02Z","Action":"fail","Test":"TestX","Elapsed":1}'
if [ "${FAKE_GO_LARGE:-0}" = 1 ]; then
for ((i=0; i<10000; i++)); do printf '%s\n' '{"Action":"output","Output":"draining after recorder failure\n"}'; done
fi
echo 'fixture stderr' >&2
if [ "${FAKE_GO_LARGE_STDERR:-0}" = 1 ]; then
for ((i=0; i<10000; i++)); do echo 'stderr draining after recorder failure' >&2; done
fi
exit "${FAKE_GO_EXIT:-0}"
EOF
chmod +x "$root/bin/go"
export PATH="$root/bin:$PATH"
code=0
FAKE_GO_EXIT=7 bash "$here/record-go-test.sh" "$root/go-test.json" -run TestX >"$root/console" 2>"$root/stderr" || code=$?
test "$code" = 7
grep -q 'fixture output' "$root/console"
grep -q 'fixture stderr' "$root/go-test.stderr"
"${PYTHON:-python3}" -c 'import json,sys; events=[json.loads(s) for s in open(sys.argv[1])]; assert len(events)==3; assert events[-1]["Elapsed"]==1; assert events[-1]["Time"]=="2026-12-02T00:00:02Z"' "$root/go-test.json"
FAKE_GO_EXIT=0 bash "$here/record-go-test.sh" "$root/go-test.json" -run TestX >"$root/console" 2>"$root/stderr"
test "$(wc -l <"$root/go-test.json")" = 6
# The evidence destination cannot be opened (a file where its parent belongs).
# The original Go success/failure must still be the command's answer.
echo occupied >"$root/not-a-directory"
code=0
FAKE_GO_EXIT=0 bash "$here/record-go-test.sh" "$root/not-a-directory/go-test.json" >"$root/console" 2>"$root/stderr" || code=$?
test "$code" = 0
grep -q 'fixture output' "$root/console"
code=0
FAKE_GO_EXIT=7 bash "$here/record-go-test.sh" "$root/not-a-directory/go-test.json" >"$root/console" 2>"$root/stderr" || code=$?
test "$code" = 7
if [ "$(uname -s)" = Linux ] && [ -c /dev/full ]; then
ln -s /dev/full "$root/full.json"
FAKE_GO_LARGE=1 FAKE_GO_EXIT=0 bash "$here/record-go-test.sh" "$root/full.json" >"$root/console" 2>"$root/stderr"
grep -q 'draining after recorder failure' "$root/console"
grep -q 'test evidence unavailable' "$root/stderr"
fi
# The recorder itself dies after its first bytes (a crash, an OOM kill): the
# rest of a large stream still drains and Go's own status is the answer.
cat >"$root/bin/dead-recorder" <<'EOF2'
#!/usr/bin/env bash
head -c 100 >/dev/null
exit 3
EOF2
chmod +x "$root/bin/dead-recorder"
for want in 0 7; do
code=0
PYTHON="$root/bin/dead-recorder" FAKE_GO_LARGE=1 FAKE_GO_EXIT=$want bash "$here/record-go-test.sh" "$root/dead.json" >"$root/console" 2>"$root/stderr" || code=$?
test "$code" = "$want"
grep -q 'draining after recorder failure' "$root/console"
grep -q 'the recorder exited' "$root/stderr"
# The stderr reader dies with a large stderr still to come.
code=0
PYTHON="$root/bin/dead-recorder" FAKE_GO_LARGE_STDERR=1 FAKE_GO_EXIT=$want bash "$here/record-go-test.sh" "$root/dead.json" >"$root/console" 2>"$root/stderr" || code=$?
test "$code" = "$want"
grep -q 'stderr draining after recorder failure' "$root/stderr"
# The recorder cannot start at all (no such interpreter).
code=0
PYTHON="$root/bin/no-such-python" FAKE_GO_LARGE=1 FAKE_GO_LARGE_STDERR=1 FAKE_GO_EXIT=$want bash "$here/record-go-test.sh" "$root/dead.json" >"$root/console" 2>"$root/stderr" || code=$?
test "$code" = "$want"
grep -q 'draining after recorder failure' "$root/console"
grep -q 'stderr draining after recorder failure' "$root/stderr"
done
echo 'record-go-test: output, timestamp, elapsed, append, dead-recorder and exit-status controls PASS'