Skip to content

Load Testing (k6) ​

Run k6 load tests against a project's local WordPress site without installing k6 on your machine.

bash
wdg <project> k6 <run|list> [options]

Each run starts a throwaway grafana/k6:1.8.3 container, streams k6's output to your terminal, and removes the container when the test ends. Nothing keeps running between runs, and there is nothing to add or remove first.

Run a test ​

bash
wdg my-site k6 run smoke                                   # check that k6 reaches the site
wdg my-site k6 run load --vus=50 --duration=2m --paths=/,/events/
wdg my-site k6 run portal.js                               # a script in projects/my-site/loadtests/
wdg my-site k6 list                                        # built-in tests and your scripts
OptionMeaning
--paths=/,/about/Comma-separated paths to request (default /)
--vus=NUsers at the plateau (load) or the first step (stress)
--duration=1mPlateau (load) or step (stress) length, as a k6 duration (30s, 2m, 1h)

k6 run exits with k6's exit code, so a failed threshold or check fails the command. Ctrl-C stops the run; k6 still prints its end-of-test summary.

The first run creates projects/<project>/loadtests/results/. Each run writes two files there, named after the test and a timestamp:

FileContents
<test>-<timestamp>.logEverything k6 printed, including the end-of-test summary
<test>-<timestamp>.jsonk6's summary export (metrics, checks, thresholds)

Built-in tests ​

TestWhat it doesFails when
smokeOne user requests each path onceAny request errors or returns 4xx/5xx
loadRamps to --vus users (default 20) over 30s, holds for --duration (default 1m), ramps downOver 1% of requests fail, or p95 exceeds 2s
stressSteps through 1x, 2x, 3x and 4x of --vus (default 25), each held for --duration (default 1m)Over 5% of requests fail, or p95 exceeds 5s; every step runs either way

Redirects are not followed, so a 3xx counts as a pass. The built-in tests live in cli/templates/k6-tests/ and are mounted read-only on each run, so platform updates reach every project. A bare name such as smoke always means the built-in test; name a project script with its .js extension.

Your own scripts ​

Put scripts in projects/<project>/loadtests/, in subfolders if you like, and run them by path relative to that folder:

bash
wdg my-site k6 run portal.js
wdg my-site k6 run checkout/guest.js

The folder is mounted into the container at /loadtests, which is also the working directory, so a script's relative open() calls (fixtures, cookie files) resolve the same way they do on disk. The container runs as your host user, so results stay owned by you.

Each run also sets K6_RUN_NAME to the run's name, so a script's handleSummary() can name its own result files.

How it reaches the site ​

The platform proxy publishes HTTPS on the host's loopback only, so the container cannot use https://my-site.localhost:<port>. It joins wdg-network and connects to the proxy container directly. Every run sets:

VariableValue
K6_ORIGINhttps://wdg-nginx
K6_HOSTmy-site.localhost:<NGINX_HTTPS_PORT>
K6_PATHS, K6_VUS, K6_DURATIONFrom --paths, --vus and --duration, when given

Scripts request K6_ORIGIN, send Host: K6_HOST, and set insecureSkipTLSVerify: true:

javascript
import http from 'k6/http';

export const options = { insecureSkipTLSVerify: true, vus: 5, duration: '30s' };

export default function () {
	http.get( `${ __ENV.K6_ORIGIN }/`, { headers: { Host: __ENV.K6_HOST }, redirects: 0 } );
}

wdg-nginx must be running (wdg start).

For logged-in pages, mint session cookies with wdg my-site wp eval-file into a file in the loadtests folder created with mode 600, and keep the folder out of any git repository.