From b37cd0ce4cb42f8fd7a1ebef0173b577ff744ecc Mon Sep 17 00:00:00 2001 From: NolanTrem <34580718+NolanTrem@users.noreply.github.com> Date: Wed, 18 Dec 2024 09:49:32 -0800 Subject: [PATCH 1/2] Add tests for rate limits --- .github/workflows/rate-limit-test.yml | 20 +++++++++++ py/tests/rateLimit.bash | 48 +++++++++++++++++++++++++++ 2 files changed, 68 insertions(+) create mode 100644 .github/workflows/rate-limit-test.yml create mode 100755 py/tests/rateLimit.bash diff --git a/.github/workflows/rate-limit-test.yml b/.github/workflows/rate-limit-test.yml new file mode 100644 index 000000000..3c7624bec --- /dev/null +++ b/.github/workflows/rate-limit-test.yml @@ -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/rate-limit-test.sh + ./py/tests/rate-limit-test.sh diff --git a/py/tests/rateLimit.bash b/py/tests/rateLimit.bash new file mode 100755 index 000000000..96ff5d16a --- /dev/null +++ b/py/tests/rateLimit.bash @@ -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 \ No newline at end of file From b7345d82eb62a94dbcf0fd82a6b3dd09e7227279 Mon Sep 17 00:00:00 2001 From: NolanTrem <34580718+NolanTrem@users.noreply.github.com> Date: Wed, 18 Dec 2024 09:53:37 -0800 Subject: [PATCH 2/2] Path --- .github/workflows/rate-limit-test.yml | 8 ++++---- py/tests/rateLimit.bash | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/.github/workflows/rate-limit-test.yml b/.github/workflows/rate-limit-test.yml index 3c7624bec..287dd89b8 100644 --- a/.github/workflows/rate-limit-test.yml +++ b/.github/workflows/rate-limit-test.yml @@ -10,11 +10,11 @@ on: jobs: test: runs-on: ubuntu-latest - + steps: - uses: actions/checkout@v3 - + - name: Run rate limit test run: | - chmod +x ./py/tests/rate-limit-test.sh - ./py/tests/rate-limit-test.sh + chmod +x ./py/tests/rateLimit.bash + ./py/tests/rateLimit.bash diff --git a/py/tests/rateLimit.bash b/py/tests/rateLimit.bash index 96ff5d16a..0f19132f4 100755 --- a/py/tests/rateLimit.bash +++ b/py/tests/rateLimit.bash @@ -30,7 +30,7 @@ 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)) @@ -40,9 +40,9 @@ for ((i=1; i<=TOTAL_REQUESTS; i++)); do else echo -e "\033[31mRequest $i: HTTP $RESPONSE (Error)\033[0m" fi - + sleep $SLEEP_INTERVAL done # Check final results -check_exit_status \ No newline at end of file +check_exit_status