Skip to content
Ameen Abozaid
Planned lessonMID-046-L02

Writing k6 scenarios

  • Lesson 2 of 6
  • Mid-level
On This Lesson 4 topics

This lesson is planned. The outline below lists the topics it will cover. The full lesson has not been published yet.

In this lesson

script a realistic user journey in k6.

Planned topics

  • k6 scripts are JavaScript: options (load shape, thresholds) and a default function (one user iteration).
  • Use checks for correctness and thresholds for pass or fail.
  • Add think time (sleep) between steps; real users pause.
  • Parametrize data (users, SKUs) so caches are not unrealistically warm.
  • Run the load generator on a separate machine from the system under test. Verify tool version before recording; Gatling is an alternative.
Draft outline details

Demonstration

javascript
export const options = { thresholds: { http_req_duration: ['p(95)<300'], http_req_failed: ['rate<0.001'] } };
export default function () {
  http.get(`${BASE}/products?q=${pick(terms)}`); sleep(2);
  http.post(`${BASE}/cart`, JSON.stringify({sku: pick(skus), qty: 1}), params); sleep(3);
}

Check your understanding

What does a threshold do?

Show answer

Fails the run when a metric violates the limit.

Practice

Apply this lesson with the module's lab, exercises and quiz.

Lab and exercises Quiz

Marking a lesson complete is optional and you can undo it any time. Your progress stays in this browser.

Continue to next lesson

Type to search levels, phases, modules and lessons.