|
#!/bin/bash
|
|
|
|
# Focused test for routing fix verification
|
|
|
|
set -e
|
|
|
|
echo "=== Routing Fix Verification Test ==="
|
|
echo ""
|
|
|
|
# Kill any existing proxy
|
|
pkill -f rproxy || true
|
|
sleep 1
|
|
|
|
# Start proxy with debug logging
|
|
echo "Starting proxy with debug logging..."
|
|
DEBUG=1 ./rproxy > proxy_test.log 2>&1 &
|
|
PROXY_PID=$!
|
|
sleep 2
|
|
|
|
# Check if proxy is running
|
|
if ! ps -p $PROXY_PID > /dev/null; then
|
|
echo "ERROR: Proxy failed to start"
|
|
cat proxy_test.log
|
|
exit 1
|
|
fi
|
|
|
|
echo "Proxy started with PID: $PROXY_PID"
|
|
echo ""
|
|
|
|
# Test function
|
|
test_endpoint() {
|
|
local endpoint=$1
|
|
local name=$2
|
|
|
|
echo "Testing $name..."
|
|
response=$(curl -s -o /dev/null -w "%{http_code}" "http://localhost:8888$endpoint" 2>/dev/null)
|
|
if [ "$response" = "200" ]; then
|
|
echo " ✓ Got 200 OK"
|
|
return 0
|
|
else
|
|
echo " ✗ Got HTTP $response"
|
|
return 1
|
|
fi
|
|
}
|
|
|
|
# Run 20 rapid tests alternating between dashboard and API
|
|
echo "=== Rapid Alternating Tests (20 requests) ==="
|
|
success=0
|
|
fail=0
|
|
|
|
for i in {1..10}; do
|
|
# Test dashboard
|
|
if test_endpoint "/dashboard" "Dashboard #$i"; then
|
|
((success++))
|
|
else
|
|
((fail++))
|
|
fi
|
|
|
|
# Test API stats
|
|
if test_endpoint "/api/stats" "API Stats #$i"; then
|
|
((success++))
|
|
else
|
|
((fail++))
|
|
fi
|
|
done
|
|
|
|
echo ""
|
|
echo "Results: $success/20 successful"
|
|
echo ""
|
|
|
|
# Test pipelined requests
|
|
echo "=== Testing Pipelined Requests ==="
|
|
echo "Sending 2 pipelined requests..."
|
|
response=$(echo -ne "GET /dashboard HTTP/1.1\r\nHost: localhost\r\nConnection: keep-alive\r\n\r\nGET /api/stats HTTP/1.1\r\nHost: localhost\r\nConnection: close\r\n\r\n" | nc localhost 8888 2>/dev/null | grep -c "HTTP/1.1 200 OK" || echo "0")
|
|
|
|
if [ "$response" = "2" ]; then
|
|
echo " ✓ Both pipelined requests handled correctly"
|
|
else
|
|
echo " ✗ Only $response/2 pipelined requests handled"
|
|
fi
|
|
echo ""
|
|
|
|
# Check logs for incorrect forwarding
|
|
echo "=== Checking Logs for Routing Issues ==="
|
|
dashboard_internal=$(grep -c "ROUTING-INTERNAL.*DASHBOARD" proxy_test.log || echo "0")
|
|
api_internal=$(grep -c "ROUTING-INTERNAL.*API STATS" proxy_test.log || echo "0")
|
|
dashboard_forward=$(grep -c "ROUTING-FORWARD.*dashboard" proxy_test.log || echo "0")
|
|
api_forward=$(grep -c "ROUTING-FORWARD.*api/stats" proxy_test.log || echo "0")
|
|
|
|
echo "Dashboard handled internally: $dashboard_internal times"
|
|
echo "API stats handled internally: $api_internal times"
|
|
echo "Dashboard forwarded (should be 0): $dashboard_forward times"
|
|
echo "API stats forwarded (should be 0): $api_forward times"
|
|
echo ""
|
|
|
|
# Final verdict
|
|
if [ "$dashboard_forward" -eq 0 ] && [ "$api_forward" -eq 0 ] && [ "$fail" -eq 0 ]; then
|
|
echo "✅ SUCCESS: All internal routes handled correctly!"
|
|
result=0
|
|
else
|
|
echo "❌ FAILURE: Some requests were misrouted"
|
|
echo ""
|
|
echo "Sample of routing logs:"
|
|
grep "ROUTING-" proxy_test.log | tail -20
|
|
result=1
|
|
fi
|
|
|
|
# Cleanup
|
|
echo ""
|
|
echo "Cleaning up..."
|
|
kill $PROXY_PID 2>/dev/null || true
|
|
wait $PROXY_PID 2>/dev/null || true
|
|
echo "Done."
|
|
|
|
exit $result |