Skip to content

Commit 68684e6

Browse files
authored
Merge pull request #386 from Code102SoftwareProject/dev
Dev
2 parents f005c0e + 50336d9 commit 68684e6

18 files changed

Lines changed: 771 additions & 39 deletions

File tree

load-tests/auth-load-test.yml

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,62 @@
1+
config:
2+
target: 'http://localhost:3000'
3+
phases:
4+
# Test with authenticated users
5+
- duration: 60
6+
arrivalRate: 10
7+
name: "Authenticated user load"
8+
- duration: 120
9+
arrivalRate: 20
10+
name: "Heavy authenticated load"
11+
12+
# Mock JWT tokens for testing (you'll need to replace with real tokens)
13+
variables:
14+
authToken: "your-jwt-token-here"
15+
16+
scenarios:
17+
- name: "Authenticated API Testing"
18+
weight: 100
19+
flow:
20+
# Test authenticated endpoints
21+
- post:
22+
url: "/api/auth/login"
23+
headers:
24+
Content-Type: "application/json"
25+
json:
26+
email: "test@example.com"
27+
password: "testpassword"
28+
capture:
29+
- json: "$.token"
30+
as: "authToken"
31+
expect:
32+
- statusCode: [200, 401, 404]
33+
34+
- think: 1
35+
36+
# Test messages API with auth
37+
- get:
38+
url: "/api/messages"
39+
headers:
40+
Authorization: "Bearer {{ authToken }}"
41+
expect:
42+
- statusCode: [200, 401]
43+
44+
- think: 2
45+
46+
# Test meetings API with auth
47+
- get:
48+
url: "/api/meeting"
49+
headers:
50+
Authorization: "Bearer {{ authToken }}"
51+
expect:
52+
- statusCode: [200, 401]
53+
54+
- think: 1
55+
56+
# Test user profile
57+
- get:
58+
url: "/api/users/profile"
59+
headers:
60+
Authorization: "Bearer {{ authToken }}"
61+
expect:
62+
- statusCode: [200, 401, 400]

load-tests/basic-load-test.yml

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
config:
2+
target: 'http://localhost:3000'
3+
phases:
4+
# Warm up phase - 5 users over 30 seconds
5+
- duration: 30
6+
arrivalRate: 5
7+
name: "Warm up"
8+
# Ramp up phase - gradually increase to 20 users over 2 minutes
9+
- duration: 120
10+
arrivalRate: 5
11+
rampTo: 20
12+
name: "Ramp up load"
13+
# Sustained load - 20 users for 3 minutes
14+
- duration: 180
15+
arrivalRate: 20
16+
name: "Sustained load"
17+
# Peak load test - 50 users for 1 minute
18+
- duration: 60
19+
arrivalRate: 50
20+
name: "Peak load"
21+
22+
scenarios:
23+
- name: "Browse and interact with app"
24+
weight: 100
25+
flow:
26+
# Test homepage
27+
- get:
28+
url: "/"
29+
expect:
30+
- statusCode: 200
31+
32+
# Test API endpoints (without auth for now)
33+
- get:
34+
url: "/api/health"
35+
expect:
36+
- statusCode: [200, 404] # 404 is OK if endpoint doesn't exist
37+
38+
# Test static assets
39+
- get:
40+
url: "/next.svg"
41+
expect:
42+
- statusCode: 200
43+
44+
# Simulate user thinking time
45+
- think: 2
46+
47+
# Test another page (if exists)
48+
- get:
49+
url: "/login"
50+
expect:
51+
- statusCode: [200, 404]
52+
53+
- think: 1

load-tests/run-tests.bat

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
@echo off
2+
echo 🚀 Artillery Load Testing for Skill-Swap-Hub
3+
echo ============================================
4+
5+
REM Check if Artillery is installed
6+
where artillery >nul 2>nul
7+
if %ERRORLEVEL% NEQ 0 (
8+
echo ❌ Artillery is not installed. Please install it first:
9+
echo npm install -g artillery
10+
pause
11+
exit /b 1
12+
)
13+
14+
REM Check if Next.js server is running
15+
powershell -Command "try { Invoke-WebRequest -Uri http://localhost:3000 -UseBasicParsing -ErrorAction Stop } catch { exit 1 }" >nul 2>nul
16+
if %ERRORLEVEL% NEQ 0 (
17+
echo ❌ Next.js server is not running on localhost:3000
18+
echo Please start your server first: npm run dev
19+
pause
20+
exit /b 1
21+
)
22+
23+
echo ✅ Server is running, starting load tests...
24+
echo.
25+
26+
echo Select which test to run:
27+
echo 1^) Basic Load Test ^(recommended for first run^)
28+
echo 2^) Authentication Load Test
29+
echo 3^) Stress Test ^(find breaking point^)
30+
echo 4^) Run All Tests ^(this will take ~20 minutes^)
31+
echo.
32+
33+
set /p choice=Enter your choice (1-4):
34+
35+
if "%choice%"=="1" goto basic
36+
if "%choice%"=="2" goto auth
37+
if "%choice%"=="3" goto stress
38+
if "%choice%"=="4" goto all
39+
goto invalid
40+
41+
:basic
42+
echo 📊 Running Basic Load Test...
43+
echo Started at: %date% %time%
44+
echo ----------------------------------------
45+
artillery run load-tests\basic-load-test.yml
46+
echo ----------------------------------------
47+
echo ✅ Basic Load Test completed at: %date% %time%
48+
goto end
49+
50+
:auth
51+
echo 📊 Running Authentication Load Test...
52+
echo Started at: %date% %time%
53+
echo ----------------------------------------
54+
artillery run load-tests\auth-load-test.yml
55+
echo ----------------------------------------
56+
echo ✅ Authentication Load Test completed at: %date% %time%
57+
goto end
58+
59+
:stress
60+
echo 📊 Running Stress Test...
61+
echo Started at: %date% %time%
62+
echo ----------------------------------------
63+
artillery run load-tests\stress-test.yml
64+
echo ----------------------------------------
65+
echo ✅ Stress Test completed at: %date% %time%
66+
goto end
67+
68+
:all
69+
echo 🔥 Running all tests - this will take approximately 20 minutes...
70+
echo 📊 Running Basic Load Test...
71+
artillery run load-tests\basic-load-test.yml
72+
timeout /t 10 /nobreak >nul
73+
echo 📊 Running Authentication Load Test...
74+
artillery run load-tests\auth-load-test.yml
75+
timeout /t 10 /nobreak >nul
76+
echo 📊 Running Stress Test...
77+
artillery run load-tests\stress-test.yml
78+
echo 🎉 All tests completed!
79+
goto end
80+
81+
:invalid
82+
echo ❌ Invalid choice. Exiting...
83+
pause
84+
exit /b 1
85+
86+
:end
87+
echo.
88+
echo 📈 Load testing completed!
89+
echo Check the results above for:
90+
echo - Response times ^(min, max, median, p95, p99^)
91+
echo - Request rates ^(req/sec^)
92+
echo - Error rates
93+
echo - Concurrent user handling capacity
94+
pause

load-tests/run-tests.sh

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
#!/bin/bash
2+
3+
echo "🚀 Artillery Load Testing for Skill-Swap-Hub"
4+
echo "============================================"
5+
6+
# Check if Artillery is installed
7+
if ! command -v artillery &> /dev/null
8+
then
9+
echo "❌ Artillery is not installed. Please install it first:"
10+
echo "npm install -g artillery"
11+
exit 1
12+
fi
13+
14+
# Check if Next.js server is running
15+
if ! curl -s http://localhost:3000 > /dev/null; then
16+
echo "❌ Next.js server is not running on localhost:3000"
17+
echo "Please start your server first: npm run dev"
18+
exit 1
19+
fi
20+
21+
echo "✅ Server is running, starting load tests..."
22+
echo ""
23+
24+
# Function to run a test
25+
run_test() {
26+
local test_name=$1
27+
local test_file=$2
28+
29+
echo "📊 Running $test_name..."
30+
echo "Test file: $test_file"
31+
echo "Started at: $(date)"
32+
echo "----------------------------------------"
33+
34+
artillery run "$test_file"
35+
36+
echo "----------------------------------------"
37+
echo "$test_name completed at: $(date)"
38+
echo ""
39+
}
40+
41+
# Menu for test selection
42+
echo "Select which test to run:"
43+
echo "1) Basic Load Test (recommended for first run)"
44+
echo "2) Authentication Load Test"
45+
echo "3) Stress Test (find breaking point)"
46+
echo "4) Run All Tests (this will take ~20 minutes)"
47+
echo ""
48+
49+
read -p "Enter your choice (1-4): " choice
50+
51+
case $choice in
52+
1)
53+
run_test "Basic Load Test" "load-tests/basic-load-test.yml"
54+
;;
55+
2)
56+
run_test "Authentication Load Test" "load-tests/auth-load-test.yml"
57+
;;
58+
3)
59+
run_test "Stress Test" "load-tests/stress-test.yml"
60+
;;
61+
4)
62+
echo "🔥 Running all tests - this will take approximately 20 minutes..."
63+
run_test "Basic Load Test" "load-tests/basic-load-test.yml"
64+
sleep 10
65+
run_test "Authentication Load Test" "load-tests/auth-load-test.yml"
66+
sleep 10
67+
run_test "Stress Test" "load-tests/stress-test.yml"
68+
echo "🎉 All tests completed!"
69+
;;
70+
*)
71+
echo "❌ Invalid choice. Exiting..."
72+
exit 1
73+
;;
74+
esac
75+
76+
echo "📈 Load testing completed!"
77+
echo "Check the results above for:"
78+
echo "- Response times (min, max, median, p95, p99)"
79+
echo "- Request rates (req/sec)"
80+
echo "- Error rates"
81+
echo "- Concurrent user handling capacity"

load-tests/stress-test.yml

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
config:
2+
target: 'http://localhost:3000'
3+
phases:
4+
# Stress test - find breaking point
5+
- duration: 60
6+
arrivalRate: 10
7+
name: "Light load"
8+
- duration: 120
9+
arrivalRate: 50
10+
name: "Medium load"
11+
- duration: 180
12+
arrivalRate: 100
13+
name: "Heavy load"
14+
- duration: 120
15+
arrivalRate: 200
16+
name: "Stress load"
17+
- duration: 60
18+
arrivalRate: 300
19+
name: "Breaking point"
20+
21+
scenarios:
22+
- name: "Stress test scenario"
23+
weight: 100
24+
flow:
25+
- get:
26+
url: "/"
27+
expect:
28+
- statusCode: [200, 500, 503]
29+
30+
- think: 0.5
31+
32+
- get:
33+
url: "/api/health"
34+
expect:
35+
- statusCode: [200, 404, 500, 503]

0 commit comments

Comments
 (0)