# Website Load and Stress Testing (k6)

This folder contains ready-to-run `k6` tests for your website.

## Files
- `scripts/load.js`: Baseline load test for expected traffic.
- `scripts/stress.js`: Stress test to find the breaking point.
- `scripts/smoke.js`: Quick health check before larger runs.

## Prerequisites
Install `k6`:

```bash
brew install k6
```

## Environment variables
Set these before running:

- `BASE_URL` (required): Target site URL, for example `https://staging.example.com`
- `REQUEST_TIMEOUT` (optional): Default `10s`
- `THINK_TIME` (optional): Default `1`

Load test tuning:
- `LOAD_VUS` (optional): Default `50`
- `LOAD_RAMP_UP` (optional): Default `2m`
- `LOAD_HOLD` (optional): Default `10m`
- `LOAD_RAMP_DOWN` (optional): Default `2m`

Stress test tuning:
- `STRESS_STAGE_1_VUS` (optional): Default `100`
- `STRESS_STAGE_1_DURATION` (optional): Default `3m`
- `STRESS_STAGE_2_VUS` (optional): Default `300`
- `STRESS_STAGE_2_DURATION` (optional): Default `3m`
- `STRESS_STAGE_3_VUS` (optional): Default `600`
- `STRESS_STAGE_3_DURATION` (optional): Default `3m`
- `STRESS_STAGE_4_VUS` (optional): Default `1000`
- `STRESS_STAGE_4_DURATION` (optional): Default `3m`
- `STRESS_RAMP_DOWN` (optional): Default `2m`

Thresholds:
- `MAX_ERROR_RATE` (optional): Default `0.01`
- `P95_MS` (optional): Default `500`

## Endpoints under test
By default, scripts hit these paths:
- `/`
- `/products`
- `/contact`

You can change the `PATHS` list inside each script if your routes differ.

## Run commands

1) Smoke test (quick check):

```bash
BASE_URL=https://your-site.com k6 run scripts/smoke.js
```

2) Load test (expected traffic):

```bash
BASE_URL=https://your-site.com k6 run scripts/load.js
```

3) Stress test (beyond expected traffic):

```bash
BASE_URL=https://your-site.com k6 run scripts/stress.js
```

## Save JSON outputs

```bash
BASE_URL=https://your-site.com k6 run --summary-export results/load-summary.json scripts/load.js
BASE_URL=https://your-site.com k6 run --summary-export results/stress-summary.json scripts/stress.js
```

## Notes
- Run against staging first.
- Avoid stressing production unless traffic controls are in place.
- Keep test data and login flows realistic if you add authenticated scenarios.
