0
0
#!/usr/bin/env bash
# tests/gate.sh's shares (GATE_SHARD=i/n, `gate.sh --list <kind>`): for the staging list and the prod list, and every n from 1
# to 8 and n = the entry count, the shares 1/n to n/n are disjoint, none is empty, each keeps gate order and their union is the
# list (tests/entries.txt: 48 staging entries, the `both` ones on prod); n above the entry count, i above n and a malformed
# value are refused. Prints one line per kind and n: the size of each share. CI's `test` runs n = 1 (every entry, one
# network); the other n are the by-hand shares (scripts/ci-test.sh CI_SHARD, docs/ci-debug.md "Shares by hand").
set -euo pipefail
cd "$(dirname "$0")/.."
for kind in staging prod; do
all=$(awk -v k=$kind '!/^#/ && NF && ($2 == "both" || k == "staging") {print $1}' tests/entries.txt)
m=$(wc -l <<<"$all")
[ "$(GATE_SHARD='' tests/gate.sh --list $kind)" = "$all" ] || { echo "check-shards: $kind: no shard is not the whole list" >&2; exit 1; }
for n in 1 2 3 4 5 6 7 8 "$m"; do
union='' sizes=''
for i in $(seq "$n"); do
share=$(GATE_SHARD=$i/$n tests/gate.sh --list $kind) || { echo "check-shards: $kind $i/$n: gate.sh --list failed" >&2; exit 1; }
[ -n "$share" ] || { echo "check-shards: $kind $i/$n is empty" >&2; exit 1; }
[ "$share" = "$(grep -Fxf <(echo "$share") <<<"$all")" ] || { echo "check-shards: $kind $i/$n is not in gate order" >&2; exit 1; }
union+=$share$'\n' sizes+=" $(wc -l <<<"$share")"
done
dup=$(sort <<<"${union%$'\n'}" | uniq -d)
[ -z "$dup" ] || { echo "check-shards: $kind n=$n: in two shares: $dup" >&2; exit 1; }
diff <(sort <<<"$all") <(sort <<<"${union%$'\n'}") > /dev/null || { echo "check-shards: $kind n=$n: the union is not the list:" >&2; diff <(sort <<<"$all") <(sort <<<"${union%$'\n'}") >&2 || true; exit 1; }
echo "shards: $kind n=$n: $m entries =$sizes"
done
for bad in $((m + 1))/$((m + 1)) 2/1 0/2 1 a/b 1/0; do
if GATE_SHARD=$bad tests/gate.sh --list $kind > /dev/null 2>&1; then echo "check-shards: $kind: GATE_SHARD=$bad was not refused" >&2; exit 1; fi
done
done
[ "$(awk '!/^#/ && NF' tests/entries.txt | wc -l)" = 48 ] || { echo "check-shards: tests/entries.txt is not 48 entries" >&2; exit 1; }