Skip to content
Merged
Show file tree
Hide file tree
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
111 changes: 111 additions & 0 deletions .github/workflows/test-rate-limits.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Test Rate Limits

on:
workflow_dispatch:
inputs:
test_count:
description: "Number of requests to make (default: 110)"
required: false
default: "110"
type: string

env:
CREATE_DB_WORKER_URL: ${{ secrets.CREATE_DB_WORKER_URL }}
CLAIM_DB_WORKER_URL: ${{ secrets.CLAIM_DB_WORKER_URL }}

jobs:
test-rate-limits:
name: Test Rate Limits
runs-on: ubuntu-latest

steps:
- name: Checkout
uses: actions/checkout@v3

- name: Test Create DB Worker Rate Limits
run: |
echo "Testing create-db-worker rate limits..."
TEST_COUNT=${INPUT_TEST_COUNT:-110}

echo "Making $TEST_COUNT requests to $CREATE_DB_WORKER_URL/test"

success_count=0
rate_limited_count=0
error_count=0

for i in $(seq 1 $TEST_COUNT); do
echo "Request $i/$TEST_COUNT"
response=$(curl -s -w "%{http_code}" -o /tmp/response_$i.json "$CREATE_DB_WORKER_URL/test")
status_code=${response: -3}

if [ "$status_code" = "200" ]; then
echo " ✅ Success (200)"
((success_count++))
elif [ "$status_code" = "429" ]; then
echo " ⚠️ Rate Limited (429)"
((rate_limited_count++))
else
echo " ❌ Error ($status_code)"
((error_count++))
fi

# Small delay between requests
sleep 0.1
done

echo ""
echo "📊 Create DB Worker Results:"
echo " Success: $success_count"
echo " Rate Limited: $rate_limited_count"
echo " Errors: $error_count"
echo " Total: $TEST_COUNT"

- name: Test Claim DB Worker Rate Limits
run: |
echo "Testing claim-db-worker rate limits..."
TEST_COUNT=${INPUT_TEST_COUNT:-110}

echo "Making $TEST_COUNT requests to $CLAIM_DB_WORKER_URL/test"

success_count=0
rate_limited_count=0
error_count=0

for i in $(seq 1 $TEST_COUNT); do
echo "Request $i/$TEST_COUNT"
response=$(curl -s -w "%{http_code}" -o /tmp/response_$i.json "$CLAIM_DB_WORKER_URL/test")
status_code=${response: -3}

if [ "$status_code" = "200" ]; then
echo " ✅ Success (200)"
((success_count++))
elif [ "$status_code" = "429" ]; then
echo " ⚠️ Rate Limited (429)"
((rate_limited_count++))
else
echo " ❌ Error ($status_code)"
((error_count++))
fi

# Small delay between requests
sleep 0.1
done

echo ""
echo "📊 Claim DB Worker Results:"
echo " Success: $success_count"
echo " Rate Limited: $rate_limited_count"
echo " Errors: $error_count"
echo " Total: $TEST_COUNT"

- name: Summary
run: |
echo "🎯 Rate Limit Testing Complete!"
echo ""
echo "Both workers have been tested with ${INPUT_TEST_COUNT:-110} requests each."
echo "Check the logs above to see the rate limiting behavior."
echo ""
echo "Expected behavior:"
echo "- First few requests should succeed (200)"
echo "- Later requests should be rate limited (429)"
echo "- This confirms rate limiting is working correctly"
16 changes: 16 additions & 0 deletions claim-db-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,22 @@ export default {

const url = new URL(request.url);

// --- Test endpoint for rate limit testing ---
if (url.pathname === '/test' && request.method === 'GET') {
return new Response(
JSON.stringify({
status: 'success',
service: 'claim-db-worker',
timestamp: Date.now(),
message: 'Rate limit test endpoint - if you see this, rate limiting passed',
}),
{
status: 200,
headers: { 'Content-Type': 'application/json' },
},
);
}

// --- OAuth Callback Handler ---
if (url.pathname === '/auth/callback') {
const code = url.searchParams.get('code');
Expand Down
16 changes: 16 additions & 0 deletions create-db-worker/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,22 @@ export default {

const url = new URL(request.url);

// --- Test endpoint for rate limit testing ---
if (url.pathname === '/test' && request.method === 'GET') {
return new Response(
JSON.stringify({
status: 'success',
service: 'create-db-worker',
timestamp: Date.now(),
message: 'Rate limit test endpoint - if you see this, rate limiting passed',
}),
{
status: 200,
headers: { 'Content-Type': 'application/json' },
},
);
}

// --- Health check route ---
if (url.pathname === '/health' && request.method === 'GET') {
return new Response(JSON.stringify({ status: 'ok', service: 'create-db', timestamp: Date.now() }), {
Expand Down
79 changes: 79 additions & 0 deletions tests/test-rate-limits.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
#!/bin/bash

# Test Rate Limits Script
# Usage: ./tests/test-rate-limits.sh [test_count] [create_db_url] [claim_db_url]

# Default values
TEST_COUNT=${1:-110}
CREATE_DB_URL=${2:-"http://127.0.0.1:8787"}
CLAIM_DB_URL=${3:-"http://127.0.0.1:9999"}

echo "🧪 Testing Rate Limits"
echo "======================"
echo "Test Count: $TEST_COUNT"
echo "Create DB URL: $CREATE_DB_URL"
echo "Claim DB URL: $CLAIM_DB_URL"
echo ""

# Function to test a worker
test_worker() {
local worker_name=$1
local worker_url=$2
local endpoint="$worker_url/test"

echo "📊 Testing $worker_name rate limits..."
echo "Making $TEST_COUNT requests to $endpoint"
echo ""

success_count=0
rate_limited_count=0
error_count=0

for i in $(seq 1 $TEST_COUNT); do
echo -n "Request $i/$TEST_COUNT: "

# Make the request and capture both response body and status code
response=$(curl -s -w "%{http_code}" -o /tmp/response_$i.json "$endpoint" 2>/dev/null)
status_code=${response: -3}

case $status_code in
200)
echo "✅ Success (200)"
((success_count++))
;;
429)
echo "⚠️ Rate Limited (429)"
((rate_limited_count++))
;;
*)
echo "❌ Error ($status_code)"
((error_count++))
;;
esac

# Small delay between requests
sleep 0.1
done

echo ""
echo "📊 $worker_name Results:"
echo " Success: $success_count"
echo " Rate Limited: $rate_limited_count"
echo " Errors: $error_count"
echo " Total: $TEST_COUNT"
echo ""
}

# Test both workers
test_worker "Create DB Worker" "$CREATE_DB_URL"
test_worker "Claim DB Worker" "$CLAIM_DB_URL"

echo "🎯 Rate Limit Testing Complete!"
echo ""
echo "Expected behavior:"
echo "- First few requests should succeed (200)"
echo "- Later requests should be rate limited (429)"
echo "- This confirms rate limiting is working correctly"
echo ""
echo "💡 To test with your actual deployed URLs, run:"
echo " ./tests/test-rate-limits.sh 110 https://create-db-temp.prisma.io https://create-db.prisma.io"