Revolyssup commented on PR #12711:
URL: https://github.com/apache/apisix/pull/12711#issuecomment-3472303210

   ## Test to check number of logs match number of requests with reloads
   ```bash
   #!/bin/bash
   
   # Configurable variables
   DURATION_HOURS=${1:-1}  # Default to 1 hour if no argument provided
   RELOAD_INTERVAL=10
   LOG_FILE="logs/file.log"
   
   # Calculate duration in seconds
   DURATION_SECONDS=$((DURATION_HOURS * 3600))
   
   # Initialize counters
   START_TIME=$(date +%s)
   END_TIME=$((START_TIME + DURATION_SECONDS))
   
   echo "Starting test for $DURATION_HOURS hour(s) ($DURATION_SECONDS seconds)"
   echo "Start time: $(date)"
   echo "End time: $(date -d "@$END_TIME")"
   echo "Reload interval: $RELOAD_INTERVAL seconds"
   echo "Log file: $LOG_FILE"
   echo "----------------------------------------"
   
   # Create log file if it doesn't exist
   mkdir -p "$(dirname "$LOG_FILE")"
   touch "$LOG_FILE"
   
   # Get initial line count
   INITIAL_LINE_COUNT=$(wc -l < "$LOG_FILE" 2>/dev/null || echo 0)
   echo "Initial line count in log: $INITIAL_LINE_COUNT"
   
   # Create a temporary file for request counting
   REQUEST_FILE=$(mktemp)
   echo "Request count file: $REQUEST_FILE"
   
   # Function to send curl requests
   send_requests() {
       local count=0
       while [ $(date +%s) -lt $END_TIME ]; do
           curl -s "http://localhost:9080"; > /dev/null 2>&1
           count=$((count + 1))
           echo "request" >> "$REQUEST_FILE"
           # Small delay to prevent overwhelming the system
           sleep 0.1
       done
       echo "Sent $count requests"
   }
   
   # Function to perform reloads
   perform_reloads() {
       while [ $(date +%s) -lt $END_TIME ]; do
           sleep $RELOAD_INTERVAL
           if [ $(date +%s) -lt $END_TIME ]; then
               echo "$(date): Performing make reload..."
               make reload > /dev/null 2>&1
           fi
       done
   }
   
   # Start the reload process in background
   perform_reloads &
   RELOAD_PID=$!
   
   # Start the request sender in foreground (so we can count properly)
   echo "Starting request sender..."
   send_requests &
   REQUEST_PID=$!
   
   # Wait for the duration or until the request sender finishes
   echo "Test running... (PID: $REQUEST_PID, $RELOAD_PID)"
   wait $REQUEST_PID
   
   # Kill reload process if it's still running
   kill $RELOAD_PID 2>/dev/null
   wait $RELOAD_PID 2>/dev/null
   
   echo "----------------------------------------"
   echo "Test completed at: $(date)"
   
   # Wait a moment for any pending log writes
   sleep 10
   
   # Get final line count
   FINAL_LINE_COUNT=$(wc -l < "$LOG_FILE" 2>/dev/null || echo 0)
   LINES_ADDED=$((FINAL_LINE_COUNT - INITIAL_LINE_COUNT))
   
   # Count the number of requests from the temporary file
   REQUEST_COUNT=$(wc -l < "$REQUEST_FILE" 2>/dev/null || echo 0)
   
   echo "Final line count in log: $FINAL_LINE_COUNT"
   echo "Lines added during test: $LINES_ADDED"
   echo "Total curl requests sent: $REQUEST_COUNT"
   
   # Clean up temporary file
   rm -f "$REQUEST_FILE"
   
   # Compare results
   if [ $LINES_ADDED -eq $REQUEST_COUNT ]; then
       echo "✅ SUCCESS: Number of log lines ($LINES_ADDED) matches number of 
requests ($REQUEST_COUNT)"
       exit 0
   else
       echo "❌ FAILURE: Number of log lines ($LINES_ADDED) does not match 
number of requests ($REQUEST_COUNT)"
       echo "Difference: $((REQUEST_COUNT - LINES_ADDED))"
       exit 1
   fi
   
   ```
   
   ## Test result
   ```bash
   Fri Oct 31 03:28:05 PM IST 2025: Performing make reload...
   Fri Oct 31 03:28:15 PM IST 2025: Performing make reload...
   Fri Oct 31 03:28:26 PM IST 2025: Performing make reload...
   Fri Oct 31 03:28:37 PM IST 2025: Performing make reload...
   Sent 29079 requests
   ----------------------------------------
   Test completed at: Fri Oct 31 03:28:42 PM IST 2025
   Final line count in log: 29732
   Lines added during test: 29079
   Total curl requests sent: 29079
   ✅ SUCCESS: Number of log lines (29079) matches number of requests (29079)
   
   ```


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to