Skip to content

Commit

Permalink
Test rate limit (#1711)
Browse files Browse the repository at this point in the history
* Add tests for rate limits
  • Loading branch information
NolanTrem authored Dec 18, 2024
1 parent fbe8337 commit 91f503c
Show file tree
Hide file tree
Showing 2 changed files with 68 additions and 0 deletions.
20 changes: 20 additions & 0 deletions .github/workflows/rate-limit-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
name: Rate Limit Test

on:
push:
branches: [ main ]
pull_request:
branches: [ main ]
workflow_dispatch:

jobs:
test:
runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v3

- name: Run rate limit test
run: |
chmod +x ./py/tests/rateLimit.bash
./py/tests/rateLimit.bash
48 changes: 48 additions & 0 deletions py/tests/rateLimit.bash
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
#!/usr/bin/env bash

# Configuration
URL="https://api.cloud.sciphi.ai/v3/health"
TOTAL_REQUESTS=60
SLEEP_INTERVAL=0.05
REQUIRED_429_COUNT=20

# Initialize counters
count_429=0
count_total=0

# Function to handle exit codes
check_exit_status() {
if [ $count_429 -ge $REQUIRED_429_COUNT ]; then
echo "✅ Test passed: Got $count_429 rate limits (429s), which meets the minimum requirement of $REQUIRED_429_COUNT"
exit 0
else
echo "❌ Test failed: Only got $count_429 rate limits (429s), which is less than the required $REQUIRED_429_COUNT"
exit 1
fi
}

# Trap Ctrl+C and call check_exit_status
trap check_exit_status INT

echo "Starting rate limit test for $URL"
echo "Target: At least $REQUIRED_429_COUNT rate limits (HTTP 429)"

for ((i=1; i<=TOTAL_REQUESTS; i++)); do
RESPONSE=$(curl -s -o /dev/null -w "%{http_code}" "$URL")
count_total=$((count_total + 1))

# Color coding for different responses
if [ "$RESPONSE" = "429" ]; then
count_429=$((count_429 + 1))
echo -e "\033[33mRequest $i: HTTP $RESPONSE (Rate limit) - Total 429s: $count_429\033[0m"
elif [ "$RESPONSE" = "200" ]; then
echo -e "\033[32mRequest $i: HTTP $RESPONSE (Success)\033[0m"
else
echo -e "\033[31mRequest $i: HTTP $RESPONSE (Error)\033[0m"
fi

sleep $SLEEP_INTERVAL
done

# Check final results
check_exit_status

0 comments on commit 91f503c

Please sign in to comment.