Skip to content

Improve metrics: Maintainability Index, Comment Density, Security Vulnerabilities of Dependencies, Number of Imports #23

Improve metrics: Maintainability Index, Comment Density, Security Vulnerabilities of Dependencies, Number of Imports

Improve metrics: Maintainability Index, Comment Density, Security Vulnerabilities of Dependencies, Number of Imports #23

name: k6 Performance Tests
on:
push:
branches: [main, master, develop]
pull_request:
branches: [main, master, develop]
workflow_dispatch:
jobs:
performance-tests:
runs-on: ubuntu-latest
steps:
- name: Checkout code
uses: actions/checkout@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: "20"
cache: "npm"
- name: Install dependencies
run: npm ci
- name: Install k6
run: |
sudo gpg -k
sudo gpg --no-default-keyring --keyring /usr/share/keyrings/k6-archive-keyring.gpg --keyserver hkp://keyserver.ubuntu.com:80 --recv-keys C5AD17C747E3415A3642D57D77C6C491D6AC1D69
echo "deb [signed-by=/usr/share/keyrings/k6-archive-keyring.gpg] https://dl.k6.io/deb stable main" | sudo tee /etc/apt/sources.list.d/k6.list
sudo apt-get update
sudo apt-get install k6
- name: Start Backend Server
run: |
npm start > server.log 2>&1 &
echo $! > server.pid
env:
PORT: 3001
USE_MONGODB: false
JWT_SECRET: test-secret-key-for-ci
NODE_ENV: test
- name: Wait for server to be ready
run: |
echo "Waiting for server to start..."
for i in {1..60}; do
if curl -s http://localhost:3001/health > /dev/null 2>&1; then
echo "Server is ready after $i seconds!"
curl -s http://localhost:3001/health
exit 0
fi
echo "Waiting for server... ($i/60)"
sleep 1
done
echo "Server failed to start. Logs:"
cat server.log
exit 1
- name: Verify server with test request
run: |
echo "Testing /places/4321..."
curl -s http://localhost:3001/places/4321 | head -c 500
echo ""
echo "Testing login..."
curl -s -X POST http://localhost:3001/auth/login \
-H "Content-Type: application/json" \
-d '{"email":"user1@example.com","password":"password123"}' | head -c 300
echo ""
- name: Run Load Test - Places
run: k6 run k6/load-test-places.js
env:
BASE_URL: http://localhost:3001
- name: Run Spike Test - Places
run: k6 run k6/spike-test-places.js
env:
BASE_URL: http://localhost:3001
- name: Run Load Test - Recommendations
run: k6 run k6/load-test-recommendations.js
env:
BASE_URL: http://localhost:3001
- name: Run Spike Test - Recommendations
run: k6 run k6/spike-test-recommendations.js
env:
BASE_URL: http://localhost:3001
- name: Show server logs on failure
if: failure()
run: |
echo "=== Server Logs ==="
cat server.log || echo "No server log found"