Repository navigation
191 lines (176 loc) · 6.7 KB
/
Copy pathperformance-tests.yml
File metadata and controls
191 lines (176 loc) · 6.7 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
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
name: Performance Tests
on:
workflow_dispatch:
inputs:
users:
description: 'Concurrent users'
default: '100'
required: false
duration:
description: 'Test duration (e.g. 120s, 5m)'
default: '120s'
required: false
host:
description: 'Target host (leave blank to start local server)'
default: 'http://localhost:8000'
required: false
test_type:
description: 'Test type to run'
default: 'baseline'
required: false
type: choice
options:
- baseline
- spike
- endurance
- crud
- db_stress
- breakpoint
schedule:
# Run weekly on Monday at 02:00 UTC
- cron: '0 2 * * 1'
jobs:
load-test:
name: Run ${{ github.event.inputs.test_type || 'baseline' }} load test
runs-on: ubuntu-latest
timeout-minutes: 60
services:
postgres:
image: postgres:14
env:
POSTGRES_DB: experimentation
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_HOST_AUTH_METHOD: trust
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 10s
--health-timeout 5s
--health-retries 5
redis:
image: redis:7
ports:
- 6379:6379
options: >-
--health-cmd "redis-cli ping"
--health-interval 10s
--health-timeout 5s
--health-retries 5
env:
# Database connection (the app reads POSTGRES_SERVER for the host)
POSTGRES_SERVER: localhost
POSTGRES_HOST: localhost
POSTGRES_PORT: 5432
POSTGRES_DB: experimentation
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
# With APP_ENV=test the application derives its schema as
# test_experimentation, so the bootstrap must create the same one.
POSTGRES_SCHEMA: test_experimentation
# Redis connection
REDIS_HOST: localhost
REDIS_PORT: 6379
# Application environment
APP_ENV: test
TESTING: 'true'
SECRET_KEY: ci-load-test-secret-key-not-for-production
# AWS mocking (not needed for load tests but prevents import errors)
AWS_DEFAULT_REGION: us-east-1
AWS_ACCESS_KEY_ID: test
AWS_SECRET_ACCESS_KEY: test
steps:
- name: Checkout repository
uses: actions/checkout@v7
- name: Set up Python 3.11
uses: actions/setup-python@v7
with:
python-version: '3.11'
cache: pip
cache-dependency-path: backend/requirements.txt
- name: Install Python dependencies
working-directory: backend
run: pip install -r requirements.txt
# Fresh database: create the schema from the models and stamp the
# alembic head (see backend/app/db/bootstrap.py).
- name: Bootstrap database schema
run: python -m backend.app.db.bootstrap
# Everything the locustfiles call: the experiment sdk_contract_ab, the
# flag sdk_contract_flag, an API key, and the developer account the
# management tasks sign in as (dev@demo.com, not a superuser). The key
# is written to a file under the runner's temp directory and the
# locustfiles read it from there, so it never reaches the log.
- name: Seed the load-test fixtures
run: python -m backend.scripts.seed_sdk_contract
env:
SDK_CONTRACT_KEY_DIR: ${{ runner.temp }}/load-test-keys
- name: Start API server
working-directory: backend
run: |
python -m uvicorn backend.app.main:app \
--host 0.0.0.0 \
--port 8000 \
--log-level warning &
echo "API server PID: $!"
# Wait for server to be ready
for i in $(seq 1 30); do
if curl -sf http://localhost:8000/health; then
echo "Server ready after ${i}s"
break
fi
echo "Waiting for server... (${i}/30)"
sleep 1
done
curl -f http://localhost:8000/health || (echo "Server failed to start" && exit 1)
env:
PYTHONPATH: ${{ github.workspace }}
- name: Determine locustfile path
id: locustfile
run: |
TEST_TYPE="${{ github.event.inputs.test_type || 'baseline' }}"
case "$TEST_TYPE" in
baseline) FILE="backend/tests/performance/locustfiles/api_load_test.py" ;;
spike) FILE="backend/tests/performance/locustfiles/spike_test.py" ;;
endurance) FILE="backend/tests/performance/locustfiles/endurance_test.py" ;;
crud) FILE="backend/tests/performance/locustfiles/crud_load_test.py" ;;
db_stress) FILE="backend/tests/performance/locustfiles/db_stress_test.py" ;;
breakpoint) FILE="backend/tests/performance/locustfiles/breakpoint_test.py" ;;
*) FILE="backend/tests/performance/locustfiles/api_load_test.py" ;;
esac
echo "locustfile=$FILE" >> "$GITHUB_OUTPUT"
echo "Using locustfile: $FILE"
# --sla report: the run fails when a request fails (Locust exits 1),
# when nothing was recorded, or when a target the locustfile declares
# in TARGETS was not recorded. Latency and throughput are printed
# beside the targets and NOT gated: one run's timings on a shared
# runner are not a stable statistic, and budgets are Phase 2 (QA L2).
- name: Run load tests
working-directory: ${{ github.workspace }}
run: |
python backend/tests/performance/run_load_tests.py \
--host "${{ github.event.inputs.host || 'http://localhost:8000' }}" \
--users "${{ github.event.inputs.users || '50' }}" \
--spawn-rate 10 \
--duration "${{ github.event.inputs.duration || '60s' }}" \
--locustfile "${{ steps.locustfile.outputs.locustfile }}" \
--csv-prefix /tmp/locust_results \
--sla report
env:
PYTHONPATH: ${{ github.workspace }}
LOAD_TEST_API_KEY_FILE: ${{ runner.temp }}/load-test-keys/.api_key
- name: Upload Locust CSV results
if: always()
uses: actions/upload-artifact@v7
with:
name: locust-results-${{ github.event.inputs.test_type || 'baseline' }}-${{ github.run_number }}
path: /tmp/locust_*.csv
retention-days: 30
- name: Upload Locust history CSV
if: always()
uses: actions/upload-artifact@v7
with:
name: locust-history-${{ github.event.inputs.test_type || 'baseline' }}-${{ github.run_number }}
path: /tmp/locust_*_history.csv
if-no-files-found: ignore
retention-days: 30