interplane.Get Omega
Read in your language

cortex

aien-dev/cortex

Brought by drakestapleton

branch main Branches Tags History

cortex / tests / big / run.sh

47 lines · 2904 bytes Raw Blame History
1#!/bin/sh
2# String-space capacity: the short-string pool must hold more than one 16 MiB omc pool.
3# Usage: sh tests/big/run.sh SNAPSHOT.db [CONTROL_BINARY]
4# Pads every entity's metadata with 3000 bytes (json_set on a scratch copy), imports it, starts
5# build/cortex on BIG_PORT (default 18291) and reads back the LAST entity, whose strings lie past
6# 16 MiB. PASS = the server loads the log and returns that entity with the exact pad from SQLite.
7# With CONTROL_BINARY (a build with one 16 MiB pool) the same log must NOT load (trap 9, exit 109):
8# the negative control showing the test reaches the old limit.
9set -u
10R=$(cd "$(dirname "$0")/../.." && pwd)
11SNAP=$1; CTL=${2:-}
12P=${BIG_PORT:-18291}
13W=${WORK:-$R/build/big}
14CORTEX_TOKEN=big-test-token; export CORTEX_TOKEN
15rm -rf "$W"; mkdir -p "$W"
16PID=
17stop() { [ -n "$PID" ] && kill "$PID" 2>/dev/null; PID=; sleep 1; }
18fail() { echo "FAIL big: $*"; stop; exit 1; }
19cp "$SNAP" "$W/s.db"
20sqlite3 "$W/s.db" "update entities set metadata_json = json_set(coalesce(metadata_json,'{}'), '\$.pad', hex(randomblob(1500)));" || fail "padding"
21hsb=$(sqlite3 "$W/s.db" "select sum(length(cast(id as blob))+length(cast(space_id as blob))+length(cast(entity_type as blob))+length(cast(canonical_name as blob))+length(cast(aliases_json as blob))+length(cast(metadata_json as blob))) from entities")
22echo "short-string bytes in the padded snapshot: $hsb (one pool: 16777216)"
23[ "$hsb" -gt 16777216 ] || fail "padding did not pass 16 MiB"
24"$R/build/cortex-import" "$W/s.db" "$W/cx.log" > "$W/import.out" 2>&1 || fail "import: $(cat "$W/import.out")"
25last=$(sqlite3 "$W/s.db" "select id from entities where retracted = 0 order by rowid desc limit 1")
26space=$(sqlite3 "$W/s.db" "select space_slug from entities where id='$last'")
27want=$(sqlite3 "$W/s.db" "select json_extract(metadata_json,'\$.pad') from entities where id='$last'")
28if [ -n "$CTL" ]; then
29 timeout 60 "$CTL" --port "$P" --log "$W/cx.log" --encoder-url http://127.0.0.1:9 > "$W/ctl.out" 2>&1 < /dev/null
30 rc=$?
31 [ "$rc" = 109 ] || fail "control binary exit $rc, expected 109 (trap 9: string pool full)"
32 echo "control: one-pool build exits 109 (trap 9) on this log"
33fi
34setsid nohup "$R/build/cortex" --port "$P" --log "$W/cx.log" --encoder-url http://127.0.0.1:9 > "$W/srv.out" 2>&1 < /dev/null &
35PID=$!
36i=0
37until curl -s -o /dev/null --max-time 1 "http://127.0.0.1:$P/health"; do
38 kill -0 "$PID" 2>/dev/null || { PID=; fail "server exited: $(tail -c 300 "$W/srv.out")"; }
39 i=$((i + 1)); [ $i -lt 600 ] || fail "server did not come up"
40 sleep 0.2
41done
42curl -s -H "authorization: Bearer $CORTEX_TOKEN" "http://127.0.0.1:$P/api/cortex/get?id=$last&space=$space" > "$W/get.json"
43stop
44case $(cat "$W/get.json") in
45 *"$want"*) echo "PASS big: last entity read back with its 3000-byte pad, past 16 MiB of short strings" ;;
46 *) fail "last entity read-back differs: $(head -c 300 "$W/get.json")" ;;
47esac