# K6 Load Testing — Goodgo Platform

## Overview

Performance load tests for critical API paths using [K6](https://k6.io/).

## Test Suites

| Script | Target | Peak VUs | Duration |
|--------|--------|----------|----------|
| `auth.js` | Login/Register | 100 | 2min |
| `listings.js` | Search + Detail | 500 | 3min |
| `search.js` | Text + Geo search | 200 | 3min |
| `payments.js` | Create + List | 50 | 2min |

## SLA Thresholds

| Metric | Threshold |
|--------|-----------|
| p50 latency | < 200ms |
| p95 latency | < 500ms |
| p99 latency | < 1000ms |
| Error rate | < 1% |

## Prerequisites

```bash
# Install K6
brew install k6        # macOS
# or: https://grafana.com/docs/k6/latest/set-up/install-k6/

# Start the API
pnpm --filter @goodgo/api run dev
```

## Running Tests

```bash
# Run individual suite
k6 run load-tests/scripts/auth.js
k6 run load-tests/scripts/listings.js
k6 run load-tests/scripts/search.js
k6 run load-tests/scripts/payments.js

# Run against a custom API URL
k6 run -e API_BASE_URL=https://staging.goodgo.vn load-tests/scripts/auth.js

# Run all suites sequentially
for f in load-tests/scripts/*.js; do k6 run "$f"; done

# Export results as JSON
k6 run --out json=results/auth.json load-tests/scripts/auth.js
```

## CI Integration

The `load-test.yml` workflow runs as an optional manual stage in GitHub Actions.
Trigger via `workflow_dispatch` with a suite selector.

## Directory Structure

```
load-tests/
├── lib/
│   └── config.js          # Shared config, helpers, SLA thresholds
├── scripts/
│   ├── auth.js            # Auth flow load tests
│   ├── listings.js        # Listings search + detail
│   ├── search.js          # Full-text + geo search
│   └── payments.js        # Payment creation + listing
└── README.md
```
