Sample Project
Table of Contents
Download
⬇ Download the k6 sample (.zip)
Every code block in this track comes from this project. The zip is rebuilt from k6/sample/ in the repository every time the site is built, so it always matches the pages.
You need k6 v2.2.0 and the Pizza Playground running.
What is inside
k6/
├── README.md Same script and switch reference as this page
└── sample/
├── lib/config.js BASE_URL, load profiles for the six test types
├── lib/auth.js login(), authHeaders(), resetPlayground()
├── lib/data.js customers from the CSV, one per VU
├── lib/flow.js menu, create order, pay, wait until paid
├── data/customers.csv The 20 playground customer logins
├── results/ Where 05-load-model.js saves its summary JSON
├── 01-first-test.js
├── 02-auth.js
├── 03-order-flow.js
├── 04-thresholds.js
└── 05-load-model.js
Run it
unzip k6-sample.zip
cd k6/sample
k6 run 01-first-test.js
| Script | Command | Explained on |
|---|---|---|
01-first-test.js | k6 run 01-first-test.js | k6 Concepts |
02-auth.js | k6 run 02-auth.js | Auth, Correlation and Data |
03-order-flow.js | k6 run 03-order-flow.js | Auth, Correlation and Data |
04-thresholds.js | k6 run 04-thresholds.js | Checks and Thresholds |
05-load-model.js | k6 run -e PROFILE=load -e SCALE=0.02 05-load-model.js (a dry run; unscaled it takes about 31.5 minutes) | Load Model |
The -e switches
Pass any of these with -e NAME=value, e.g. k6 run -e PROFILE=stress -e USERS=20 05-load-model.js.
| Name | Meaning | Default | Read by |
|---|---|---|---|
BASE_URL | Target base URL | http://127.0.0.1:8080 | lib/config.js, used by every script |
USERS | Peak VUs. For arrival-rate executors it sizes the VU pool, not the rate: preAllocatedVUs = USERS, maxVUs = USERS × 5 | 10 | 05-load-model.js |
SCALE | Shrinks every stage duration for a dry run | 1 | 05-load-model.js |
PROFILE | smoke, load, stress, endurance or spike | smoke | 05-load-model.js |
EXECUTOR | Which k6 executor to use, or mixed | ramping-vus | 05-load-model.js |
RATE | Iterations per second for arrival-rate executors | 5 | 05-load-model.js |
THINK | Think time between iterations (seconds) | 1 | 05-load-model.js |
AUTOPAY | false sends orders through the mock gateway | true | 03-order-flow.js, 04-thresholds.js |
MOCK_DELAY | Extra gateway latency in ms (X-Mock-Delay) | none | 03-order-flow.js |
CUSTOMER_VUS | VUs in 02-auth.js's per-VU login scenario | 5 | 02-auth.js |