interplane.Get Omega
Read in your language

interplane-forge

INTERPLANE Forge

Brought by drakestapleton

branch main Branches Tags History

interplane-forge / collab / tests / cache.sh

59 lines · 4326 bytes Raw Blame History
1#!/bin/bash
2# collab/tests/cache.sh: HOST test of the raw-diff cache bound (collab/co8cache.om). A test forged on
3# PORT (default 18494) with a private data dir, reading the real store and allow-list (read-only), is
4# built with the cache cap cut from 2 GiB to 560000 bytes and the per-file limit from 512 MiB to
5# 21000000 bytes, so four omega-mv patch diffs (git diff --full-index) exercise both: A 35e5e0f7
6# (408064 bytes), B 3ccb2109 (146266), C 4dd099df (28595), D 88050ef7 (21431680). Eviction removes the least recently used file
7# (status-change time; a cache hit refreshes it) until the total is within the cap.
8# Usage: collab/tests/cache.sh (CORES default 14; KEEP=1 keeps the temp dir)
9set -u
10H=$(cd "$(dirname "$0")" && pwd)
11export PORT=${CACHE_PORT:-18494} CORES=${CORES:-14}
12T=$(mktemp -d /tmp/cpcache.XXXXXX)
13PASS=0; FAIL=0
14ok() { PASS=$((PASS+1)); echo "PASS $*"; }
15bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; }
16check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want $2, got $1"; fi; }
17CAP=560000
18mkdir -p "$T/data"
19DATA=$T/data/ SEDX="s/^ret 2147483648\$/ret $CAP/;s/^ret 536870912\$/ret 21000000/" "$H/tbuild.sh" "$T/forged" || exit 1
20grep -q "^ret $CAP\$" "$T/forged.om" && grep -q '^ret 21000000$' "$T/forged.om" && ok "test caps compiled in" || { bad "test caps not in the build"; exit 1; }
21FORGE_SOCIAL_DIR=$T/data/ taskset -c "$CORES" nice -n 10 "$T/forged" 2>> "$T/forged.err" &
22PID=$!
23trap 'kill $PID 2>/dev/null; wait $PID 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT
24U="http://127.0.0.1:$PORT/drakestapleton/omega-mv/patches"
25for i in $(seq 50); do curl -s -o /dev/null "$U" && break; sleep 0.1; done
26kill -0 $PID 2> /dev/null || { echo "test forged did not start: $(cat "$T/forged.err")"; exit 1; }
27A=35e5e0f7475f70926524f953d73a1a77dd5c6f8b; B=3ccb2109969f959f135192aafcad2ae7dc42c596
28C=4dd099df31792d5ddb0d9fac5ca6d568513f4539; D=88050ef7d710cb43d65214ff50bb1a0882770bb9
29get() { sleep 0.2; curl -s -o "$T/$2" -w '%{http_code}' "$U/$1.diff"; }
30files() { ls "$T/data/collab/"*/ 2>/dev/null | grep '\.diff$'; }
31# newname: the one cache file not yet named (each patch's file is named on its first fetch)
32newname() { files | grep -v -x -F -e "${F_A:-x}" -e "${F_B:-x}" -e "${F_C:-x}"; }
33present() { local out=""; for p in A B C; do eval "f=\${F_$p:-}"; [ -n "$f" ] && files | grep -q -x -F -e "$f" && out="$out$p"; done; echo "$out"; }
34total() { find "$T/data/collab" -type f -name '*.diff' -printf '%s\n' 2>/dev/null | awk '{s+=$1} END {print s+0}'; }
35c=$(get $D d); check "$c" 500 "NEG 21431680-byte diff over the per-file limit refused"
36grep -q 'larger than 512 MiB' "$T/d" && ok "refusal says so" || bad "refusal text: $(head -c 200 "$T/d")"
37check "$(files | wc -l)" 0 "NEG refused diff not kept"
38c=$(get $A a1); check "$c" 200 "A"; F_A=$(newname)
39c=$(get $B b1); check "$c" 200 "B"; F_B=$(newname)
40check "$(present)" "AB" "NEG A+B = 554330 <= cap: nothing evicted"
41c=$(get $C c1); check "$c" 200 "C"; F_C=$(newname)
42check "$(present)" "BC" "A+B+C = 582925 > cap: only the oldest (A) evicted"
43[ "$(total)" -le $CAP ] && ok "total $(total) <= $CAP" || bad "total $(total) > $CAP"
44c=$(get $B b2); check "$c" 200 "B again (cache hit refreshes it)"
45cmp -s "$T/b1" "$T/b2" && ok "hit serves the same bytes" || bad "B changed"
46c=$(get $A a2); check "$c" 200 "A again (rebuilt)"
47cmp -s "$T/a1" "$T/a2" && check "$(wc -c < "$T/a2")" 408064 "rebuilt A identical" || bad "A differs"
48check "$(present)" "AB" "B refreshed, so C (now least recent) evicted, not B"
49[ "$(total)" -le $CAP ] && ok "total $(total) <= $CAP" || bad "total $(total) > $CAP"
50# NEG: a cache file under the pre---full-index name (<base>-<head>.diff, abbreviated index lines) is
51# never served: remove B's file, plant STALE at the old name, the next fetch rebuilds the full diff
52SD=$(dirname "$(find "$T/data/collab" -type f -name "$F_B")")
53OLD=${F_B%.full.diff}; OLD=${OLD%.diff}.diff
54rm -f "$SD/$F_B"; printf STALE > "$SD/$OLD"
55case "$F_B" in *.full.diff) ok "cache name $F_B";; *) bad "cache name $F_B is not <base>-<head>.full.diff";; esac
56c=$(get $B b3); check "$c" 200 "B after an old-name file was planted"
57cmp -s "$T/b1" "$T/b3" && ok "NEG old-name .diff not served (rebuilt, $(wc -c < "$T/b3") bytes)" || bad "B served $(head -c 40 "$T/b3")"
58echo "collab cache: $PASS passed, $FAIL failed"
59[ "$FAIL" = 0 ]