-
Notifications
You must be signed in to change notification settings - Fork 116
154 lines (134 loc) · 5.08 KB
/
Copy pathscalability-testing.yml
File metadata and controls
154 lines (134 loc) · 5.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
name: Scalability Testing
on:
push:
branches: [main]
pull_request:
branches: [main]
workflow_dispatch:
inputs:
concurrency_limit:
description: 'Max concurrency level to test'
required: false
default: '100'
type: string
jobs:
# ── Scalability unit tests (always run) ───────────────────────────────────
scalability-unit:
name: Scalability Unit Tests
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.3.0
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Run scalability tests
run: npx vitest run backend/tests/scalability.test.js --reporter=verbose
env:
NODE_ENV: test
- name: Upload scalability test results
if: always()
uses: actions/upload-artifact@v4
with:
name: scalability-results-${{ github.sha }}
path: test-reports/
retention-days: 30
# ── Load-based scalability tests (main branch or manual trigger) ──────────
scalability-load:
name: Scalability Load Tests
runs-on: ubuntu-latest
if: |
github.ref == 'refs/heads/main' ||
github.event_name == 'workflow_dispatch'
services:
postgres:
image: postgres:16
env:
POSTGRES_USER: future_admin
POSTGRES_PASSWORD: test_password
POSTGRES_DB: future_test
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
ports:
- 5433:5432
steps:
- uses: actions/checkout@11bd71901bbe5b1630ceea73d27597364c9af683 # v4.2.2
- uses: actions/setup-node@49933ea5288caeca8642d1e84afbd3f7d6820020 # v4.3.0
with:
node-version: '20'
cache: 'npm'
- name: Install dependencies
run: npm ci
- name: Start backend server
run: |
cp backend/.env.example backend/.env
node backend/src/server.js &
echo "SERVER_PID=$!" >> $GITHUB_ENV
for i in $(seq 1 15); do
curl -sf http://localhost:3001/health && break
echo "Waiting for server... ($i/15)"
sleep 2
done
env:
NODE_ENV: test
DATABASE_URL: postgresql://future_admin:test_password@localhost:5433/future_test
PORT: 3001
- 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 -y
- name: Run concurrent users scalability test
run: |
k6 run \
--out json=backend/data/load-tests/scalability-concurrent-${{ github.sha }}.json \
backend/load-tests/k6/scenarios/concurrent-users.js
env:
BASE_URL: http://localhost:3001
MAX_VUS: ${{ github.event.inputs.concurrency_limit || '100' }}
- name: Run API endpoint scalability test
run: |
k6 run \
--out json=backend/data/load-tests/scalability-endpoints-${{ github.sha }}.json \
backend/load-tests/k6/scenarios/api-endpoints.js
env:
BASE_URL: http://localhost:3001
- name: Stop backend server
if: always()
run: kill $SERVER_PID || true
- name: Upload k6 scalability results
if: always()
uses: actions/upload-artifact@v4
with:
name: scalability-k6-results-${{ github.sha }}
path: backend/data/load-tests/scalability-*.json
retention-days: 30
# ── Scalability recommendations comment on PR ─────────────────────────────
scalability-summary:
name: Scalability Summary
runs-on: ubuntu-latest
needs: scalability-unit
if: always() && github.event_name == 'pull_request'
steps:
- uses: actions/github-script@60a0d83039c74a4aee543508d2ffcb1c3799cdea # v7.0.1
with:
script: |
const status = '${{ needs.scalability-unit.result }}';
const icon = status === 'success' ? '✅' : '❌';
github.rest.issues.createComment({
issue_number: context.issue.number,
owner: context.repo.owner,
repo: context.repo.repo,
body: `## Scalability Test Report\n\n${icon} **Scalability unit tests: ${status}**\n\nFull load-based scalability tests run on \`main\` branch merges. See \`scalability-results\` artifact for details.`
});