Skip to main content

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
ScriptCommandExplained on
01-first-test.jsk6 run 01-first-test.jsk6 Concepts
02-auth.jsk6 run 02-auth.jsAuth, Correlation and Data
03-order-flow.jsk6 run 03-order-flow.jsAuth, Correlation and Data
04-thresholds.jsk6 run 04-thresholds.jsChecks and Thresholds
05-load-model.jsk6 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.

NameMeaningDefaultRead by
BASE_URLTarget base URLhttp://127.0.0.1:8080lib/config.js, used by every script
USERSPeak VUs. For arrival-rate executors it sizes the VU pool, not the rate: preAllocatedVUs = USERS, maxVUs = USERS × 51005-load-model.js
SCALEShrinks every stage duration for a dry run105-load-model.js
PROFILEsmoke, load, stress, endurance or spikesmoke05-load-model.js
EXECUTORWhich k6 executor to use, or mixedramping-vus05-load-model.js
RATEIterations per second for arrival-rate executors505-load-model.js
THINKThink time between iterations (seconds)105-load-model.js
AUTOPAYfalse sends orders through the mock gatewaytrue03-order-flow.js, 04-thresholds.js
MOCK_DELAYExtra gateway latency in ms (X-Mock-Delay)none03-order-flow.js
CUSTOMER_VUSVUs in 02-auth.js's per-VU login scenario502-auth.js