#!/bin/bash
# Extended test: more runs per gap to see steady-state behavior

echo "=== EXTENDED GAP TIMING TEST ==="
echo "Running 5 jobs per gap interval to see steady-state"
echo ""

rm -f /tmp/soprano_timing_debug.txt

test_gap() {
    local gap=$1
    echo "========================================"
    echo "Testing ${gap}s gap (5 runs)"
    echo "========================================"
    
    for i in {1..5}; do
        echo "Run $i at $(date +%H:%M:%S)"
        curl -s -X POST http://localhost:8765/api/speak \
            -H "Content-Type: application/json" \
            -d "{\"text\": \"Extended test run $i with ${gap} second gap to find steady state performance.\"}" \
            > /dev/null
        sleep $gap
    done
    
    echo "Waiting 10s for last job..."
    sleep 10
    echo ""
}

# Test 9s gap (between known good 10s and bad 8s)
echo "TEST 1: 9s gap"
test_gap 9

# Test 7s gap  
echo "TEST 2: 7s gap"
test_gap 7

echo ""
echo "========================================"
echo "RESULTS"
echo "========================================"
cat /tmp/soprano_timing_debug.txt | grep -E "Realtime|Avg RVC" | paste - - | awk '{print NR ". " $3 " realtime, RVC: " $6}'
