Watch
0
0
Fork
You've already forked hyperhive
0

fetch the secrets unit's store leaves concurrently and log how long each phase takes

This commit is contained in:
atlas 2026-11-04 17:04:35 +01:00
commit 197caa1e52

View file

@ -22,7 +22,7 @@ setup() {
dir=$(mktemp -d)
mkdir "$dir/kv"
export FAKE_BAO_KV=$dir/kv FAKE_BAO_LOG=$dir/bao.log FAKE_BAO_LOGIN_RC=0
unset FAKE_BAO_DENY_READ FAKE_BAO_DENY_WRITE FAKE_BAO_RACE FAKE_BAO_READ_TIMEOUT FAKE_BAO_READ_5XX
unset FAKE_BAO_DENY_READ FAKE_BAO_DENY_WRITE FAKE_BAO_RACE FAKE_BAO_READ_TIMEOUT FAKE_BAO_READ_5XX FAKE_BAO_READ_DELAY PREFETCH
: >"$FAKE_BAO_LOG"
earlier=$dir/earlier
minted=$dir/minted
@ -34,7 +34,8 @@ mint() {
printf 'minted-value\n'
}
# run — `store_seeded` for $leaf and $earlier with the stub first on PATH.
# run — `store_seeded` for $leaf and $earlier with the stub first on PATH, after
# `store_prefetch` of the leaf when $PREFETCH is set.
# Sets $rc and $got.
run() {
got=$(
@ -45,6 +46,7 @@ run() {
. "$HELPER"
store_init
store_login 2>>"$dir/err"
[ -z "${PREFETCH-}" ] || store_prefetch "$leaf" 2>>"$dir/err"
store_seeded "$leaf" "$earlier" mint 2>"$dir/err"
)
rc=$?
@ -212,6 +214,90 @@ run
expect 1 ""
if ran_mint; then fail "minted with no store to hold the value"; fi
# kv_gets: how many `kv get` calls the stub logged.
kv_gets() {
grep -c '^kv get' "$FAKE_BAO_LOG" || true
}
setup "prefetch: a leaf the store holds is read once, and the result is the same"
PREFETCH=1
printf 'stored-value' >"$stored"
printf 'old-value\n' >"$earlier"
run
expect 0 stored-value
held stored-value
no_write
no_mint
if [ "$(kv_gets)" != 1 ]; then fail "$(kv_gets) reads, wanted 1"; fi
setup "prefetch: a leaf the store lacks is seeded from the file as without it"
PREFETCH=1
printf 'old-value\n' >"$earlier"
run
expect 0 old-value
held old-value
if ran_mint; then fail "minted although the file held a value"; fi
setup "prefetch: a refused read uses the file's value, writes nothing and prints the refusal, as without it"
PREFETCH=1
printf 'old-value\n' >"$earlier"
export FAKE_BAO_DENY_READ=1 FAKE_BAO_DENY_WRITE=1
run
expect 0 old-value
held ""
no_write
no_mint
err_has "could not read $leaf from the swarm secret store"
err_has "permission denied"
setup "prefetch: a read that times out is not treated as an absent leaf"
PREFETCH=1
printf 'stored-value' >"$stored"
export FAKE_BAO_READ_TIMEOUT=1
run
expect 1 ""
held stored-value
no_write
no_mint
err_has "(exit status 124)"
setup "prefetch: a store that refuses the login reads nothing"
PREFETCH=1
printf 'old-value\n' >"$earlier"
export FAKE_BAO_LOGIN_RC=1
run
expect 0 old-value
if grep -q '^kv' "$FAKE_BAO_LOG"; then fail "called kv after a refused login"; fi
setup "prefetch: many leaves are read together, at most 8 at once, each once, and a second read of one asks the store"
export FAKE_BAO_READ_DELAY=0.3
many=()
for i in $(seq 1 20); do
many+=("secret/swarm/many/$i")
printf 'v%s' "$i" >"$FAKE_BAO_KV/$(printf '%s' "secret/swarm/many/$i" | tr / _)"
done
want=$(for i in $(seq 1 20); do printf 'v%s\n' "$i"; done)
got=$(
set -e
PATH="$FAKE_BAO_BIN:$PATH"
unset BAO_TOKEN
# shellcheck source=/dev/null
. "$HELPER"
store_init
store_login
store_prefetch "${many[@]}"
for l in "${many[@]}"; do
store_read "$l"
echo
done
store_read "${many[0]}"
)
if [ "$got" != "$want"$'\n'v1 ]; then fail "values differ: $got"; fi
if [ "$(kv_gets)" != 21 ]; then fail "$(kv_gets) reads, wanted 20 and the second read of one"; fi
peak=$(sort -n "$FAKE_BAO_KV/.peak" | tail -1)
if [ "$peak" -gt 8 ]; then fail "$peak reads in flight, wanted at most 8"; fi
if [ "$peak" -lt 2 ]; then fail "$peak read in flight, the reads did not overlap"; fi
if [ "$failures" != 0 ]; then
echo "$failures of $count cases failed" >&2
exit 1