#!/usr/bin/env bash # Sustained stress stage for CUBELinux-2 (invoked by `./check stress`). # # Builds cube-server + cubec from THIS workspace tree, spins a fresh daemon on a # throwaway socket + store, then drives it hard for STRESS_SECONDS (default 150) # with real prog/run traffic while sampling the per-command latency + per-C # namespace telemetry. This exercises the new cubesys `stats` path under load. # # It deliberately does NOT touch the production daemon (real socket/store in # /home/luulu/.cubelinux) so it is safe to run any time. Numbers are # informational; the stage passes iff the gate passed and the daemon survives. set -uo pipefail REPO="$(cd "$(dirname "$0")/.." && pwd)" cd "$REPO" export PATH="$HOME/.cargo/bin:/usr/local/bin:/usr/bin:/bin:$PATH" command -v cargo >/dev/null || { echo "cargo not found" >&2; exit 127; } JOBS="${JOBS:-4}" SECS="${STRESS_SECONDS:-150}" echo "building cube-server + cubec from tree ($REPO) ..." cargo build -p cubesys --release --bins --jobs "$JOBS" >/dev/null 2>&1 || { echo "BUILD FAILED (cubesys bins)"; exit 1 } SRV="$REPO/target/release/cube-server" CLI="$REPO/target/release/cubec" [ -x "$SRV" ] && [ -x "$CLI" ] || { echo "binaries missing after build"; exit 1; } TMPD="$(mktemp -d /tmp/cube-stress.XXXXXX)" SOCK="$TMPD/cube.sock" STORE="$TMPD/store.json" trap 'kill $DPID 2>/dev/null; wait $DPID 2>/dev/null; rm -rf "$TMPD"' EXIT echo "starting stress daemon on $SOCK ..." # Legacy clients (cubec in this script) send no HELLO, so run the daemon in # anonymous-allowed mode; owner enforcement is exercised by the unit/ad-hoc # verifiers, not the stress harness. "$SRV" --socket "$SOCK" --store "$STORE" --allow-anonymous >"$TMPD/daemon.log" 2>&1 & DPID=$! # wait for socket (max ~15s) for i in $(seq 1 15); do [ -S "$SOCK" ] && break; sleep 1; done [ -S "$SOCK" ] || { echo "daemon failed to start (see $TMPD/daemon.log)"; kill $DPID 2>/dev/null; exit 1; } START=$(date +%s) END=$((START + SECS)) PAIRS=0 SAMPLE_EVERY=25 # sample stats every 25 pairs (~ once a second at load) while [ "$(date +%s)" -lt "$END" ]; do X=$((PAIRS % 256)) "$CLI" --socket "$SOCK" "prog /c077/z001/y001/x$X const $((PAIRS % 97)) halt" >/dev/null 2>&1 "$CLI" --socket "$SOCK" "run /c077/z001/y001/x$X" >/dev/null 2>&1 PAIRS=$((PAIRS + 1)) if [ "$((PAIRS % SAMPLE_EVERY))" -eq 0 ]; then echo "--- [$(date -u +%H:%M:%S)] stress sample $((PAIRS / SAMPLE_EVERY)) (pairs=$PAIRS) ---" "$CLI" --socket "$SOCK" "stats" || true fi done # final health snapshot echo "--- final stats (pairs driven: $PAIRS over ~${SECS}s) ---" "$CLI" --socket "$SOCK" "stats" || true ELAPSED=$(($(date +%s) - START)) if [ "$ELAPSED" -lt 1 ]; then ELAPSED=1; fi echo "stress throughput: ~$((PAIRS / ELAPSED)) prog+run pairs/s (informational)" echo "STRESS STAGE OK (daemon alive, $PAIRS pairs driven)" exit 0