Interplane page as plain text, for reading tools and agents. English is the reference text: translate it with your own tool. Text in backticks and in ``` blocks (commands, fingerprints, file names) and link targets in <...> are exact: copy them, never translate them. Page: /drakestapleton/interplane-forge/blob/main/collab/tests/cache.sh # interplane-forge INTERPLANE Forge Brought by drakestapleton Sign in to star 0 stars 0 watching About Files History Releases Proposed changes Issues For developers 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) 9 set -u 10 H=$(cd "$(dirname "$0")" && pwd) 11 export PORT=${CACHE_PORT:-18494} CORES=${CORES:-14} 12 T=$(mktemp -d /tmp/cpcache.XXXXXX) 13 PASS=0; FAIL=0 14 ok() { PASS=$((PASS+1)); echo "PASS $*"; } 15 bad() { FAIL=$((FAIL+1)); echo "FAIL $*"; } 16 check() { if [ "$1" = "$2" ]; then ok "$3 ($1)"; else bad "$3: want $2, got $1"; fi; } 17 CAP=560000 18 mkdir -p "$T/data" 19 DATA=$T/data/ SEDX="s/^ret `2147483648`\$/ret $CAP/;s/^ret `536870912`\$/ret `21000000`/" "$H/tbuild.sh" "$T/forged" || exit 1 20 grep -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; } 21 FORGE_SOCIAL_DIR=$T/data/ taskset -c "$CORES" nice -n 10 "$T/forged" 2>> "$T/forged.err" & 22 PID=$! 23 trap 'kill $PID 2>/dev/null; wait $PID 2>/dev/null; [ -n "${KEEP:-}" ] || rm -rf "$T"' EXIT 24 U="http://127.0.0.1:$PORT/drakestapleton/omega-mv/patches" 25 for i in $(seq 50); do curl -s -o /dev/null "$U" && break; sleep 0.1; done 26 kill -0 $PID 2> /dev/null || { echo "test forged did not start: $(cat "$T/forged.err")"; exit 1; } 27 A=`35e5e0f7475f70926524f953d73a1a77dd5c6f8b`; B=`3ccb2109969f959f135192aafcad2ae7dc42c596` 28 C=`4dd099df31792d5ddb0d9fac5ca6d568513f4539`; D=`88050ef7d710cb43d65214ff50bb1a0882770bb9` 29 get() { sleep 0.2; curl -s -o "$T/$2" -w '%{http_code}' "$U/$1.diff"; } 30 files() { 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) 32 newname() { files | grep -v -x -F -e "${F_A:-x}" -e "${F_B:-x}" -e "${F_C:-x}"; } 33 present() { 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"; } 34 total() { find "$T/data/collab" -type f -name '*.diff' -printf '%s\n' 2>/dev/null | awk '{s+=$1} END {print s+0}'; } 35 c=$(get $D d); check "$c" 500 "NEG `21431680`-byte diff over the per-file limit refused" 36 grep -q 'larger than 512 MiB' "$T/d" && ok "refusal says so" || bad "refusal text: $(head -c 200 "$T/d")" 37 check "$(files | wc -l)" 0 "NEG refused diff not kept" 38 c=$(get $A a1); check "$c" 200 "A"; F_A=$(newname) 39 c=$(get $B b1); check "$c" 200 "B"; F_B=$(newname) 40 check "$(present)" "AB" "NEG A+B = 554330 <= cap: nothing evicted" 41 c=$(get $C c1); check "$c" 200 "C"; F_C=$(newname) 42 check "$(present)" "BC" "A+B+C = 582925 > cap: only the oldest (A) evicted" 43 [ "$(total)" -le $CAP ] && ok "total $(total) <= $CAP" || bad "total $(total) > $CAP" 44 c=$(get $B b2); check "$c" 200 "B again (cache hit refreshes it)" 45 cmp -s "$T/b1" "$T/b2" && ok "hit serves the same bytes" || bad "B changed" 46 c=$(get $A a2); check "$c" 200 "A again (rebuilt)" 47 cmp -s "$T/a1" "$T/a2" && check "$(wc -c < "$T/a2")" 408064 "rebuilt A identical" || bad "A differs" 48 check "$(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 (-.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 52 SD=$(dirname "$(find "$T/data/collab" -type f -name "$F_B")") 53 OLD=${F_B%.full.diff}; OLD=${OLD%.diff}.diff 54 rm -f "$SD/$F_B"; printf STALE > "$SD/$OLD" 55 case "$F_B" in *.full.diff) ok "cache name $F_B";; *) bad "cache name $F_B is not -.full.diff";; esac 56 c=$(get $B b3); check "$c" 200 "B after an old-name file was planted" 57 cmp -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")" 58 echo "collab cache: $PASS passed, $FAIL failed" 59 [ "$FAIL" = 0 ]