#!/bin/bash set -euo pipefail # TEST-208/209: Performance and load tests. # Checks system responsiveness, resource usage, and mobile performance metrics. SSH_KEY="${ARCHIPELAGO_SSH_KEY:-$HOME/.ssh/archipelago-deploy}" TARGET="archipelago@192.168.1.228" SSH_CMD="ssh -i $SSH_KEY -o StrictHostKeyChecking=no $TARGET" PASSWORD="password123" PASS=0 FAIL=0 WARN=0 RESULTS=() log() { echo -e "\033[1;34m[TEST]\033[0m $*"; } pass() { echo -e "\033[1;32m[PASS]\033[0m $*"; PASS=$((PASS + 1)); RESULTS+=("PASS: $*"); } fail() { echo -e "\033[1;31m[FAIL]\033[0m $*"; FAIL=$((FAIL + 1)); RESULTS+=("FAIL: $*"); } warn() { echo -e "\033[1;33m[WARN]\033[0m $*"; WARN=$((WARN + 1)); RESULTS+=("WARN: $*"); } main() { log "=== Performance Test Suite ===" echo "" # --- TEST-208: System Load --- log "=== TEST-208: System Load ===" # 1. Check UI load time log "1. Measuring UI load time..." local ui_time ui_time=$($SSH_CMD "curl -s -o /dev/null -w '%{time_total}' http://localhost/ 2>/dev/null" || echo "999") ui_time_ms=$(echo "$ui_time * 1000" | bc 2>/dev/null || echo "999") log " UI load time: ${ui_time}s" if (( $(echo "$ui_time < 3" | bc -l 2>/dev/null || echo 0) )); then pass "UI loads in ${ui_time}s (< 3s threshold)" else fail "UI load time ${ui_time}s exceeds 3s threshold" fi # 2. Check RPC response time log "2. Measuring RPC response time..." local rpc_time rpc_time=$($SSH_CMD "curl -s -o /dev/null -w '%{time_total}' http://localhost:5678/rpc/v1 \ -X POST -H 'Content-Type: application/json' \ -d '{\"method\":\"health\"}' 2>/dev/null" || echo "999") log " RPC response time: ${rpc_time}s" if (( $(echo "$rpc_time < 1" | bc -l 2>/dev/null || echo 0) )); then pass "RPC responds in ${rpc_time}s (< 1s)" else fail "RPC response time ${rpc_time}s exceeds 1s" fi # 3. Check memory usage log "3. Checking system memory..." local mem_info mem_info=$($SSH_CMD "free -m | awk '/Mem:/{print \$2,\$3,\$4}'") local total_mb used_mb avail_mb total_mb=$(echo "$mem_info" | awk '{print $1}') used_mb=$(echo "$mem_info" | awk '{print $2}') avail_mb=$(echo "$mem_info" | awk '{print $3}') local pct_used=$((used_mb * 100 / total_mb)) log " Memory: ${used_mb}MB / ${total_mb}MB (${pct_used}% used, ${avail_mb}MB free)" if [ "$pct_used" -lt 90 ]; then pass "Memory usage ${pct_used}% (< 90%)" else warn "Memory usage ${pct_used}% — high (>= 90%)" fi # 4. Check disk usage log "4. Checking disk usage..." local disk_pct disk_pct=$($SSH_CMD "df / | awk 'NR==2{print \$5}' | tr -d '%'") log " Disk: ${disk_pct}% used" if [ "$disk_pct" -lt 95 ]; then pass "Disk usage ${disk_pct}% (< 95%)" else warn "Disk usage ${disk_pct}% — critical (>= 95%)" fi # 5. Check running containers log "5. Counting running containers..." local container_count container_count=$($SSH_CMD "podman ps -q 2>/dev/null | wc -l") log " Running containers: $container_count" pass "$container_count containers running" # 6. Check for OOM kills log "6. Checking for OOM kills..." local oom_count oom_count=$($SSH_CMD "dmesg 2>/dev/null | grep -c 'Out of memory' || echo 0") if [ "$oom_count" -eq 0 ]; then pass "No OOM kills detected" else fail "$oom_count OOM kills detected" fi # 7. Check WebSocket connectivity log "7. Testing WebSocket endpoint..." local ws_status ws_status=$($SSH_CMD "curl -s -o /dev/null -w '%{http_code}' -H 'Upgrade: websocket' -H 'Connection: Upgrade' http://localhost:5678/ws 2>/dev/null" || echo "000") if [ "$ws_status" = "101" ] || [ "$ws_status" = "200" ] || [ "$ws_status" = "426" ]; then pass "WebSocket endpoint responds (HTTP $ws_status)" else warn "WebSocket endpoint returned HTTP $ws_status" fi # 8. Check backend service health log "8. Checking archipelago service..." local svc_status svc_status=$($SSH_CMD "systemctl is-active archipelago 2>/dev/null" || echo "inactive") if [ "$svc_status" = "active" ]; then pass "archipelago service is active" else fail "archipelago service is $svc_status" fi echo "" # --- TEST-209: Asset Size Check (proxy for mobile perf) --- log "=== TEST-209: Frontend Asset Sizes ===" # Check total JS bundle size log "9. Checking JS bundle sizes..." local js_size js_size=$($SSH_CMD "du -sb /opt/archipelago/web-ui/assets/*.js 2>/dev/null | awk '{sum+=\$1}END{print sum}'" || echo "0") local js_size_kb=$((js_size / 1024)) log " Total JS: ${js_size_kb}KB" if [ "$js_size_kb" -lt 2048 ]; then pass "JS bundle ${js_size_kb}KB (< 2MB)" else warn "JS bundle ${js_size_kb}KB — consider code splitting" fi # Check total CSS size local css_size css_size=$($SSH_CMD "du -sb /opt/archipelago/web-ui/assets/*.css 2>/dev/null | awk '{sum+=\$1}END{print sum}'" || echo "0") local css_size_kb=$((css_size / 1024)) log " Total CSS: ${css_size_kb}KB" if [ "$css_size_kb" -lt 512 ]; then pass "CSS bundle ${css_size_kb}KB (< 512KB)" else warn "CSS bundle ${css_size_kb}KB — consider purging" fi # Check gzip is enabled log "10. Checking gzip compression..." local gzip_check gzip_check=$($SSH_CMD "curl -sI -H 'Accept-Encoding: gzip' http://localhost/ 2>/dev/null | grep -i content-encoding || echo ''") if echo "$gzip_check" | grep -qi "gzip"; then pass "gzip compression enabled" else warn "gzip compression not detected in response headers" fi echo "" log "=== RESULTS ===" for r in "${RESULTS[@]}"; do echo " $r" done echo "" log "Pass: $PASS | Fail: $FAIL | Warn: $WARN" [ $FAIL -gt 0 ] && exit 1 exit 0 } main "$@"