Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
74 changes: 74 additions & 0 deletions tests-perf/append_phone_numbers.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
#!/bin/bash

# Script to append +16135550123 to a file with auto-incrementing filename
# Usage: ./append_phone_numbers.sh [base_filename] [count]

# Default base filename if none provided
BASE_FILENAME="${1:-phone_numbers}"
PHONE_NUMBER="+16135550123"
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[nitpick] The hardcoded phone number should be extracted as a configurable parameter or documented as a test-specific number. This would make the script more flexible for different testing scenarios.

Copilot uses AI. Check for mistakes.
# Default count if none provided, otherwise use second argument
COUNT="${2:-10000}"

# Function to find next available filename with timestamp
find_next_filename() {
local base="$1"
local timestamp=$(date +"%Y%m%d_%H%M")
local counter=1
local filename

# First try with timestamp
filename="${base}_${timestamp}.csv"
if [[ ! -f "$filename" ]]; then
echo "$filename"
return
fi

# Then try with incrementing numbers if timestamp file exists
while true; do
filename="${base}_${timestamp}_${counter}.csv"
if [[ ! -f "$filename" ]]; then
echo "$filename"
return
fi
((counter++))
done
}

# Get the next available filename
FILENAME=$(find_next_filename "$BASE_FILENAME")

# Validate that count is a positive number
if ! [[ "$COUNT" =~ ^[0-9]+$ ]] || [ "$COUNT" -le 0 ]; then
echo "Error: Count must be a positive integer"
echo "Usage: $0 [base_filename] [count]"
echo "Example: $0 sms 50000"
exit 1
fi

echo "Using filename: $FILENAME"
echo "Appending $PHONE_NUMBER to $FILENAME $COUNT times..."

# Add CSV header if file doesn't exist
if [[ ! -f "$FILENAME" ]]; then
echo "phone number" > "$FILENAME"
fi

# Use a for loop to append the phone number specified number of times
for ((i=1; i<=COUNT; i++)); do
echo "$PHONE_NUMBER" >> "$FILENAME"

# Show progress every 10% or every 10,000 iterations, whichever is smaller
progress_interval=$((COUNT / 10))
if [ "$progress_interval" -gt 10000 ]; then
progress_interval=10000
elif [ "$progress_interval" -lt 1000 ]; then
progress_interval=1000
Comment on lines +64 to +65
Copy link

Copilot AI Nov 17, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

When COUNT is less than 10, the progress_interval calculation results in 0, causing a division by zero error at line 68 when checking i % progress_interval == 0. Add a check to ensure progress_interval is at least 1, or skip progress reporting for very small counts.

Suggested change
elif [ "$progress_interval" -lt 1000 ]; then
progress_interval=1000
elif [ "$progress_interval" -lt 1 ]; then
progress_interval=1

Copilot uses AI. Check for mistakes.
fi

if ((i % progress_interval == 0)); then
echo "Progress: $i/$COUNT"
fi
done

echo "Completed! Added $COUNT entries to $FILENAME"
echo "File size: $(wc -l < "$FILENAME") lines"
Loading