Run load tests with vus, duration, thresholds, scenarios, synchronous http.get(), and check() assertions for CI performance gates
0 / 5 completed
1 / 5
What do vus and duration configure in a k6 test?
vus and duration:export const options = { vus: 50, duration: '30s' }. k6 maintains 50 concurrent virtual users for 30 seconds, each executing the default function in a loop. Total iterations depend on response time. Use stages instead for ramp-up/ramp-down patterns. vus: 1 with a long duration is useful for baseline measurements.
2 / 5
How does http.get() work in k6?
k6 http.get(): k6 scripts run in a modified JS runtime (Goja) where HTTP calls block synchronously — no async/await needed. const res = http.get('https://api.example.com/data') blocks until the response arrives. This simplifies test scripts. Multiple requests use http.batch() for concurrent execution within a single VU.
3 / 5
What are thresholds in k6 and how do they affect test results?
k6 thresholds: Example: export const options = { thresholds: { http_req_duration: ['p(95)<500'], http_req_failed: ['rate<0.01'] } }. k6 evaluates thresholds at the end of the test. If http_req_duration p(95) exceeds 500ms, the test exits with code 99. This integrates performance assertions into CI — a failing threshold breaks the build just like a failing unit test.
4 / 5
What is a k6 scenario and why use it instead of vus/duration?
k6 scenarios: Example: scenarios: { spike: { executor: 'ramping-vus', stages: [{ duration: '10s', target: 100 }] }, steady: { executor: 'constant-arrival-rate', rate: 10, timeUnit: '1s', duration: '60s', preAllocatedVUs: 20 } }. Scenarios run concurrently by default. constant-arrival-rate is especially useful for load testing because it maintains request throughput regardless of response time.
5 / 5
What does check() do in k6?
k6 check():check(res, { 'status is 200': (r) => r.status === 200, 'body contains id': (r) => r.json('id') !== undefined }). Returns true/false per check. Failed checks increment the checks metric's failure counter but the VU continues. Combine with thresholds: thresholds: { checks: ['rate>0.99'] } to fail the build if fewer than 99% of checks pass.