#!/bin/bash # Test server sync timing SERVER_URL="${1:-http://localhost:3000/api/send}" ROOM="${2:-test}" PASSPHRASE="${3:-test}" echo "Testing server sync timing..." echo "Server: $SERVER_URL" echo "Room: $ROOM" echo "" for i in {1..5}; do START=$(date +%s%N) RESPONSE=$(curl -s -w "\n%{http_code}\n%{time_total}" -X POST "$SERVER_URL" \ -H "Content-Type: application/json" \ -d "{ \"room\": \"$ROOM\", \"passphrase\": \"$PASSPHRASE\", \"user_name\": \"TestUser\", \"text\": \"Test message $i at $(date +%H:%M:%S)\", \"timestamp\": \"$(date +%H:%M:%S)\" }") HTTP_CODE=$(echo "$RESPONSE" | tail -n2 | head -n1) TIME_TOTAL=$(echo "$RESPONSE" | tail -n1) END=$(date +%s%N) DURATION=$(echo "scale=0; ($END - $START) / 1000000" | bc) if [ "$HTTP_CODE" = "200" ]; then echo "✓ Message $i: ${DURATION}ms (curl reports: ${TIME_TOTAL}s)" else echo "✗ Message $i: HTTP $HTTP_CODE" echo "$RESPONSE" | head -n1 fi sleep 0.2 done echo "" echo "All 5 messages sent. Check display at:" echo "http://localhost:3000/display?room=$ROOM"