| name | load-test-runner |
| description | Generate and run load test scripts for APIs and pages. Use when the user asks for load tests, stress tests, or traffic simulation scripts. |
Load Test Runner
Generate and execute load test scripts for APIs and web applications.
Description
This skill creates ready-to-run load test scripts that simulate concurrent users hitting your endpoints. It generates scripts using lightweight, zero-dependency tools (shell + curl) as well as Python scripts for more complex scenarios.
Instructions
When the user provides endpoints and performance requirements:
- Define Scenarios: Identify the load patterns to test
- Generate Scripts: Create executable load test scripts
- Configure Parameters: Set concurrent users, duration, ramp-up
- Execute Tests: Run the tests and collect metrics
- Analyze Results: Calculate percentiles, throughput, and error rates
Script Templates
Bash Load Test (Zero Dependencies)
#!/bin/bash
URL="${1:-https://api.example.com/endpoint}"
CONCURRENT="${2:-10}"
TOTAL="${3:-100}"
RESULTS_FILE="results_$(date +%Y%m%d_%H%M%S).csv"
echo "timestamp,status_code,time_total,time_connect,time_starttransfer" > "$RESULTS_FILE"
run_request() {
curl -s -o /dev/null -w "%{time_total},%{time_connect},%{time_starttransfer},%{http_code}\n" "$URL"
}
echo "Starting load test: $CONCURRENT concurrent, $TOTAL total requests"
echo "Target: $URL"
seq 1 "$TOTAL" | xargs -P "$CONCURRENT" -I {} bash -c '
result=$(curl -s -o /dev/null -w "%{time_total},%{time_connect},%{time_starttransfer},%{http_code}" "'"$URL"'")
echo "$(date +%s),$result"
' >> "$RESULTS_FILE"
echo "Test complete. Results in $RESULTS_FILE"
Python Load Test (Advanced)
"""Load Test Script - Generated by Claude QA Toolkit"""
import concurrent.futures
import requests
import time
import statistics
import json
from datetime import datetime
class LoadTestRunner:
def __init__(self, url, method="GET", headers=None, body=None):
self.url = url
self.method = method
self.headers = headers or {}
self.body = body
self.results = []
def run_request(self, request_id):
start = time.time()
try:
resp = requests.request(
self.method, self.url,
headers=self.headers,
json=self.body,
timeout=30
)
elapsed = time.time() - start
return {
"id": request_id,
"status": resp.status_code,
"time": round(elapsed * 1000, 2),
"size": len(resp.content),
"error": None
}
except Exception as e:
elapsed = time.time() - start
return {
"id": request_id,
"status": 0,
"time": round(elapsed * 1000, 2),
"size": 0,
"error": str(e)
}
def run(self, concurrent_users, total_requests, ramp_up_seconds=0):
print(f"Load Test: {concurrent_users} users, {total_requests} requests")
with concurrent.futures.ThreadPoolExecutor(max_workers=concurrent_users) as executor:
futures = [executor.submit(self.run_request, i) for i in range(total_requests)]
self.results = [f.result() for f in concurrent.futures.as_completed(futures)]
return self.analyze()
def analyze(self):
times = [r["time"] for r in self.results if r["error"] is None]
errors = [r for r in self.results if r["error"] is not None]
if not times:
return {"error": "All requests failed"}
return {
"total_requests": len(self.results),
"successful": len(times),
"failed": len(errors),
"p50_ms": round(statistics.median(times), 2),
"p90_ms": round(sorted(times)[int(len(times)*0.9)], 2),
"p95_ms": round(sorted(times)[int(len(times)*0.95)], 2),
"p99_ms": round(sorted(times)[int(len(times)*0.99)], 2),
"avg_ms": round(statistics.mean(times), 2),
"min_ms": round(min(times), 2),
"max_ms": round(max(times), 2),
"error_rate": f"{round(100*len(errors)/len(self.results),2)}%",
"throughput_rps": round(len(times) / (max(times)/1000), 2)
}
Test Scenarios
Smoke Test
- 1-2 concurrent users, 10 requests
- Verify system handles minimal load
Load Test
- Expected concurrent users, sustained for 5+ minutes
- Measure response times and error rates under normal load
Stress Test
- Gradually ramp from normal to 2-3x expected load
- Find the breaking point
Spike Test
- Sudden burst of 10x normal traffic
- Test auto-scaling and recovery
Endurance Test
- Normal load sustained for 30+ minutes
- Detect memory leaks and degradation
Example Usage
Create a load test for POST /api/orders that handles 100 concurrent users.
Include authentication headers and a sample JSON body.
Generate a stress test that ramps from 10 to 500 users over 5 minutes
for these 3 endpoints: [list endpoints]