The macOS -race gateway step split 3772 tests by sorted name into one
fixed share per core (3 on macos-latest), and the shares ran out of their
20 minutes with no test hung: run 42354008450 at 191f3c0af ended at 12m,
16m and over 20m (shard 2 in TestMediaJSONPastOldBodyLimit/images), and
42350695944 ran all three at ~19m20s. Two causes: the shares were uneven,
and a few tests scan tens of MB byte by byte, which the race detector
makes 14 to 30 times as slow.
Measured on mote (M5 Pro), -race, -test.v, old script, per test (plain
run in brackets): TestLoopGuardLeavesOrdinaryRepliesAlone 104s (7.6s),
TestLargeRequestEndpoints 104s (3.6s), TestRequestTailAfterOldLimit 33s
(4s), TestCodexBodyReadsPastOldLimit 14.6s (0.55s),
TestMediaJSONPastOldBodyLimit 10.7s (0.7s), TestCodexCompressedTailError
10.2s. Sums of test time per share: 487s, 641s, 761s.
- build/race-shards.sh: the tests go in ~118 chunks of about 32 (test N
in chunk N mod m, so TestCodex..., TestCompaction... spread out), and
each of the N workers takes the next chunk when it is done (xargs -P).
Workers end within a chunk of each other. Each chunk logs in its own
::group:: with its time; the five slowest are printed at the end. A
chunk whose process didn't finish counts as failed.
- oldBodyLimit (the pre-#118 64 MB) is 20 MB under -race
(race_on_test.go), 64 MB in the plain run. 20 MB still passes every cut
below 64 MB (bodyKept's 4 MB, the 8 MB and 16 MB reads); the plain Test
step on ubuntu and macOS still sends the full 64 MB.
- TestLoopGuardLeavesOrdinaryRepliesAlone is skipped under -race: one
goroutine feeds one loopGuard (loop_guard.go starts none), so there is
no race to find; the plain run reads the whole corpus.
After, per test on mote under -race: TestLargeRequestEndpoints 40.7s,
TestRequestTailAfterOldLimit 13.05s, TestCodexBodyReadsPastOldLimit
5.1s, TestMediaJSONPastOldBodyLimit 4.46s, TestCodexCompressedTailError
3.1s, TestLoopGuard skipped: ~210s less race time.
A/B in one window on mote (same commit, binaries built from base and
change, 3 workers, load 15 to 30): old script with old tests 12m59s
wall (red: TestTranslatedStreamKeepsClientAlive, the load-timing test
of #2711/#2737); new script with new tests 10m57s, green, slowest
chunk 62s. On 3-core CI the wall should be about the total over three
plus a chunk, instead of the slowest share.
Broken by hand (wsl-run, Linux): defaultBodyLimit 16<<20 under -race
turns TestCodexBodyReadsPastOldLimit, TestLargeRequestEndpoints and
TestRequestTailAfterOldLimit red (body rejected / 413); defaultBodyLimit
48<<20 in the plain run turns the same three red. So the race run guards
the read-whole path past 16 MB and the plain run still guards 64 MB.
TestCodexCompressedTailError and TestMediaJSONPastOldBodyLimit stay green
with either cap: they never guarded the limit (true before this change).
Run: gofmt -l; on mote GOOS=linux go vet -tags nogui ./..., GOOS=windows
go vet ./..., go vet ./..., go vet -race ./internal/gateway; the seven
touched tests plain on mote (all pass, 21.9s); the whole gateway package
under -race through the new script on mote twice (one red,
TestBurstTellsNoSpeed/responses_from_chat_burst, the load timing of
#2719; the second run green).
Not tried: the race run with a 48 MB cap (it would pass: under -race
nothing now covers 20 to 64 MB, the plain step does); a CI run before
the push.
Fixes #5361
Fixes #5320
65 lines
2.8 KiB
Bash
Executable File
65 lines
2.8 KiB
Bash
Executable File
#!/usr/bin/env bash
|
|
# race-shards.sh DIR BIN N [FLAGS]: runs the tests of BIN, a package's test
|
|
# binary (go test -c), from the package's DIR in N processes at once, and
|
|
# fails if any test process does. FLAGS go to every process. A package's
|
|
# tests run one at a time unless they call t.Parallel, which t.Setenv rules
|
|
# out, so the gateway's suite under the race detector keeps one core busy;
|
|
# N processes keep N busy. Each process isolates its own home (the
|
|
# package's TestMain).
|
|
#
|
|
# The tests go in chunks of about RACE_CHUNK (default 32), and each of the
|
|
# N workers takes the next chunk when it is done with one. A
|
|
# fixed split of the tests into N shares left one share with the slow
|
|
# tests: on macOS CI the gateway's three took 12, 16 and over 20 minutes
|
|
# (#5361, #5320), while chunks taken in turn end within a chunk of each
|
|
# other. Each chunk is a process of its own, ~1s of start-up under -race.
|
|
set -euo pipefail
|
|
pkg=$1 bin=$2 n=$3
|
|
shift 3
|
|
size=${RACE_CHUNK:-32}
|
|
dir=$(mktemp -d)
|
|
trap 'rm -rf "$dir"' EXIT
|
|
(cd "$pkg" && "$bin" -test.list '.*') | grep -E '^(Test|Example|Fuzz)' | sort >"$dir/all"
|
|
total=$(wc -l <"$dir/all" | tr -d ' ')
|
|
# the Nth test goes in chunk N mod m: tests named alike are often slow
|
|
# alike (TestCodex..., TestCompaction...), and spread they don't make one
|
|
# chunk that ends long after the rest
|
|
m=$(((total + size - 1) / size))
|
|
awk -v m="$m" -v d="$dir" '{f = sprintf("%s/c.%04d", d, NR % m); print >> f; close(f)}' "$dir/all"
|
|
printf '%s\n' "$dir"/c.* >"$dir/chunks"
|
|
echo "$total tests in $(wc -l <"$dir/chunks" | tr -d ' ') chunks of $size, $n at a time"
|
|
|
|
# run CHUNK DIR BIN FLAGS...: one chunk's tests; its log and its status and
|
|
# seconds go beside it.
|
|
cat >"$dir/run" <<'EOF'
|
|
#!/usr/bin/env bash
|
|
c=$1 pkg=$2 bin=$3
|
|
shift 3
|
|
re="^($(paste -sd'|' "$c"))\$"
|
|
start=$(date +%s)
|
|
if (cd "$pkg" && "$bin" -test.run "$re" "$@") >"$c.log" 2>&1; then st=ok; else st=FAIL; fi
|
|
echo "$st $(($(date +%s) - start))" >"$c.st"
|
|
EOF
|
|
chmod +x "$dir/run"
|
|
|
|
start=$(date +%s)
|
|
# a chunk whose process didn't finish has no status, and fails below
|
|
xargs -P "$n" -I{} "$dir/run" {} "$pkg" "$bin" "$@" <"$dir/chunks" || true
|
|
fail=0
|
|
while read -r c; do
|
|
st=FAIL secs=?
|
|
if [ -f "$c.st" ]; then read -r st secs <"$c.st"; fi
|
|
echo "::group::${c##*/} $st ($(wc -l <"$c" | tr -d ' ') tests, ${secs}s): $(head -1 "$c") .. $(tail -1 "$c")"
|
|
cat "$c.log" 2>/dev/null || true
|
|
echo "::endgroup::"
|
|
if [ "$st" != ok ]; then
|
|
fail=1
|
|
grep -E '^(--- FAIL|FAIL|panic|WARNING: DATA RACE)' "$c.log" 2>/dev/null || echo "${c##*/}: no status, its process didn't finish"
|
|
fi
|
|
done <"$dir/chunks"
|
|
echo "$total tests in $(($(date +%s) - start))s; the slowest chunks:"
|
|
while read -r c; do
|
|
if [ -f "$c.st" ]; then echo "$(cut -d' ' -f2 "$c.st")s ${c##*/}: $(head -1 "$c") .. $(tail -1 "$c")"; fi
|
|
done <"$dir/chunks" | sort -rn | head -5 || true
|
|
exit $fail
|