Skip to content

feature/tests/fix_k6_version_on_CI #3

feature/tests/fix_k6_version_on_CI

feature/tests/fix_k6_version_on_CI #3

Workflow file for this run

name: Performance Tests
on:
push:
branches: [master]
pull_request:
branches: [master]
workflow_dispatch:
inputs:
p95-ms:
description: Relax the p95 latency threshold across the smoke runs (ms)
type: string
default: '500'
error-rate:
description: Relax the error-rate threshold across the smoke runs
type: string
default: '0.01'
jobs:
validate:
name: Validate k6 scripts parse
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v4
- uses: grafana/setup-k6-action@v1
with:
k6-version: '2.1.0'
- name: k6 inspect every load script
run: |
set -euo pipefail
for script in $(find tests/performance/load -name '*.js' | sort); do
k6 inspect "$script" > /dev/null
echo "OK: $script"
done
smoke:
name: Smoke run against a live API
runs-on: ubuntu-latest
needs: validate
if: github.event_name == 'workflow_dispatch'
services:
postgres:
image: postgres:17
env:
POSTGRES_USER: postgres
POSTGRES_PASSWORD: postgres
POSTGRES_DB: performancelab_test
ports:
- 5432:5432
options: >-
--health-cmd pg_isready
--health-interval 5s
--health-timeout 5s
--health-retries 5
env:
DB_HOST: localhost
DB_PORT: 5432
DB_USER: postgres
DB_PASSWORD: postgres
DB_NAME: performancelab_test
steps:
- uses: actions/checkout@v4
- uses: astral-sh/setup-uv@v5
with:
python-version: "3.14"
- name: Install dependencies
run: uv sync --all-extras
- name: Boot the API and health-wait
run: |
uv run uvicorn api.main:app --host 0.0.0.0 --port 8000 --timeout-keep-alive 30 &
for i in $(seq 1 30); do
if curl -fsS http://localhost:8000/docs > /dev/null 2>&1; then
echo "API ready"
exit 0
fi
sleep 2
done
echo "API failed to become ready" >&2
exit 1
- uses: grafana/setup-k6-action@v1
with:
k6-version: '2.1.0'
- name: Smoke get_users
run: k6 run tests/performance/load/users/get_users.js -e K6_SCENARIO=smoke -e BASE_URL=http://localhost:8000 -e K6_P95_MS=${{ inputs.p95-ms }} -e K6_ERROR_RATE=${{ inputs.error-rate }}
- name: Smoke get_rooms
run: k6 run tests/performance/load/rooms/get_rooms.js -e K6_SCENARIO=smoke -e BASE_URL=http://localhost:8000 -e K6_P95_MS=${{ inputs.p95-ms }} -e K6_ERROR_RATE=${{ inputs.error-rate }}
- name: Smoke post_users
run: k6 run tests/performance/load/users/post_users.js -e K6_SCENARIO=smoke -e BASE_URL=http://localhost:8000 -e K6_P95_MS=${{ inputs.p95-ms }} -e K6_ERROR_RATE=${{ inputs.error-rate }}
- name: Smoke post_rooms
run: k6 run tests/performance/load/rooms/post_rooms.js -e K6_SCENARIO=smoke -e BASE_URL=http://localhost:8000 -e K6_P95_MS=${{ inputs.p95-ms }} -e K6_ERROR_RATE=${{ inputs.error-rate }}
- name: Smoke post_reservations
run: k6 run tests/performance/load/reservations/post_reservations.js -e K6_SCENARIO=smoke -e BASE_URL=http://localhost:8000 -e K6_P95_MS=${{ inputs.p95-ms }} -e K6_ERROR_RATE=${{ inputs.error-rate }}