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
62 changes: 62 additions & 0 deletions load-tests/auth-load-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
config:
target: 'http://localhost:3000'
phases:
# Test with authenticated users
- duration: 60
arrivalRate: 10
name: "Authenticated user load"
- duration: 120
arrivalRate: 20
name: "Heavy authenticated load"

# Mock JWT tokens for testing (you'll need to replace with real tokens)
variables:
authToken: "your-jwt-token-here"

scenarios:
- name: "Authenticated API Testing"
weight: 100
flow:
# Test authenticated endpoints
- post:
url: "/api/auth/login"
headers:
Content-Type: "application/json"
json:
email: "test@example.com"
password: "testpassword"
capture:
- json: "$.token"
as: "authToken"
expect:
- statusCode: [200, 401, 404]

- think: 1

# Test messages API with auth
- get:
url: "/api/messages"
headers:
Authorization: "Bearer {{ authToken }}"
expect:
- statusCode: [200, 401]

- think: 2

# Test meetings API with auth
- get:
url: "/api/meeting"
headers:
Authorization: "Bearer {{ authToken }}"
expect:
- statusCode: [200, 401]

- think: 1

# Test user profile
- get:
url: "/api/users/profile"
headers:
Authorization: "Bearer {{ authToken }}"
expect:
- statusCode: [200, 401, 400]
53 changes: 53 additions & 0 deletions load-tests/basic-load-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
config:
target: 'http://localhost:3000'
phases:
# Warm up phase - 5 users over 30 seconds
- duration: 30
arrivalRate: 5
name: "Warm up"
# Ramp up phase - gradually increase to 20 users over 2 minutes
- duration: 120
arrivalRate: 5
rampTo: 20
name: "Ramp up load"
# Sustained load - 20 users for 3 minutes
- duration: 180
arrivalRate: 20
name: "Sustained load"
# Peak load test - 50 users for 1 minute
- duration: 60
arrivalRate: 50
name: "Peak load"

scenarios:
- name: "Browse and interact with app"
weight: 100
flow:
# Test homepage
- get:
url: "/"
expect:
- statusCode: 200

# Test API endpoints (without auth for now)
- get:
url: "/api/health"
expect:
- statusCode: [200, 404] # 404 is OK if endpoint doesn't exist

# Test static assets
- get:
url: "/next.svg"
expect:
- statusCode: 200

# Simulate user thinking time
- think: 2

# Test another page (if exists)
- get:
url: "/login"
expect:
- statusCode: [200, 404]

- think: 1
94 changes: 94 additions & 0 deletions load-tests/run-tests.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
@echo off
echo 🚀 Artillery Load Testing for Skill-Swap-Hub
echo ============================================

REM Check if Artillery is installed
where artillery >nul 2>nul
if %ERRORLEVEL% NEQ 0 (
echo ❌ Artillery is not installed. Please install it first:
echo npm install -g artillery
pause
exit /b 1
)

REM Check if Next.js server is running
powershell -Command "try { Invoke-WebRequest -Uri http://localhost:3000 -UseBasicParsing -ErrorAction Stop } catch { exit 1 }" >nul 2>nul
if %ERRORLEVEL% NEQ 0 (
echo ❌ Next.js server is not running on localhost:3000
echo Please start your server first: npm run dev
pause
exit /b 1
)

echo ✅ Server is running, starting load tests...
echo.

echo Select which test to run:
echo 1^) Basic Load Test ^(recommended for first run^)
echo 2^) Authentication Load Test
echo 3^) Stress Test ^(find breaking point^)
echo 4^) Run All Tests ^(this will take ~20 minutes^)
echo.

set /p choice=Enter your choice (1-4):

if "%choice%"=="1" goto basic
if "%choice%"=="2" goto auth
if "%choice%"=="3" goto stress
if "%choice%"=="4" goto all
goto invalid

:basic
echo 📊 Running Basic Load Test...
echo Started at: %date% %time%
echo ----------------------------------------
artillery run load-tests\basic-load-test.yml
echo ----------------------------------------
echo ✅ Basic Load Test completed at: %date% %time%
goto end

:auth
echo 📊 Running Authentication Load Test...
echo Started at: %date% %time%
echo ----------------------------------------
artillery run load-tests\auth-load-test.yml
echo ----------------------------------------
echo ✅ Authentication Load Test completed at: %date% %time%
goto end

:stress
echo 📊 Running Stress Test...
echo Started at: %date% %time%
echo ----------------------------------------
artillery run load-tests\stress-test.yml
echo ----------------------------------------
echo ✅ Stress Test completed at: %date% %time%
goto end

:all
echo 🔥 Running all tests - this will take approximately 20 minutes...
echo 📊 Running Basic Load Test...
artillery run load-tests\basic-load-test.yml
timeout /t 10 /nobreak >nul
echo 📊 Running Authentication Load Test...
artillery run load-tests\auth-load-test.yml
timeout /t 10 /nobreak >nul
echo 📊 Running Stress Test...
artillery run load-tests\stress-test.yml
echo 🎉 All tests completed!
goto end

:invalid
echo ❌ Invalid choice. Exiting...
pause
exit /b 1

:end
echo.
echo 📈 Load testing completed!
echo Check the results above for:
echo - Response times ^(min, max, median, p95, p99^)
echo - Request rates ^(req/sec^)
echo - Error rates
echo - Concurrent user handling capacity
pause
81 changes: 81 additions & 0 deletions load-tests/run-tests.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
#!/bin/bash

echo "🚀 Artillery Load Testing for Skill-Swap-Hub"
echo "============================================"

# Check if Artillery is installed
if ! command -v artillery &> /dev/null
then
echo "❌ Artillery is not installed. Please install it first:"
echo "npm install -g artillery"
exit 1
fi

# Check if Next.js server is running
if ! curl -s http://localhost:3000 > /dev/null; then
echo "❌ Next.js server is not running on localhost:3000"
echo "Please start your server first: npm run dev"
exit 1
fi

echo "✅ Server is running, starting load tests..."
echo ""

# Function to run a test
run_test() {
local test_name=$1
local test_file=$2

echo "📊 Running $test_name..."
echo "Test file: $test_file"
echo "Started at: $(date)"
echo "----------------------------------------"

artillery run "$test_file"

echo "----------------------------------------"
echo "✅ $test_name completed at: $(date)"
echo ""
}

# Menu for test selection
echo "Select which test to run:"
echo "1) Basic Load Test (recommended for first run)"
echo "2) Authentication Load Test"
echo "3) Stress Test (find breaking point)"
echo "4) Run All Tests (this will take ~20 minutes)"
echo ""

read -p "Enter your choice (1-4): " choice

case $choice in
1)
run_test "Basic Load Test" "load-tests/basic-load-test.yml"
;;
2)
run_test "Authentication Load Test" "load-tests/auth-load-test.yml"
;;
3)
run_test "Stress Test" "load-tests/stress-test.yml"
;;
4)
echo "🔥 Running all tests - this will take approximately 20 minutes..."
run_test "Basic Load Test" "load-tests/basic-load-test.yml"
sleep 10
run_test "Authentication Load Test" "load-tests/auth-load-test.yml"
sleep 10
run_test "Stress Test" "load-tests/stress-test.yml"
echo "🎉 All tests completed!"
;;
*)
echo "❌ Invalid choice. Exiting..."
exit 1
;;
esac

echo "📈 Load testing completed!"
echo "Check the results above for:"
echo "- Response times (min, max, median, p95, p99)"
echo "- Request rates (req/sec)"
echo "- Error rates"
echo "- Concurrent user handling capacity"
35 changes: 35 additions & 0 deletions load-tests/stress-test.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
config:
target: 'http://localhost:3000'
phases:
# Stress test - find breaking point
- duration: 60
arrivalRate: 10
name: "Light load"
- duration: 120
arrivalRate: 50
name: "Medium load"
- duration: 180
arrivalRate: 100
name: "Heavy load"
- duration: 120
arrivalRate: 200
name: "Stress load"
- duration: 60
arrivalRate: 300
name: "Breaking point"

scenarios:
- name: "Stress test scenario"
weight: 100
flow:
- get:
url: "/"
expect:
- statusCode: [200, 500, 503]

- think: 0.5

- get:
url: "/api/health"
expect:
- statusCode: [200, 404, 500, 503]
Loading
Loading