What you will learn in this TP
- Write a k6 script
- Add checks and thresholds
- Interpret the summary
Introduction #
What you will learn in this section
- Write a k6 script
- Add checks and thresholds
- Interpret the summary
Context. An API is about to be exposed to a new partner. Before opening access, you check that it handles a modest load with acceptable latency.
Prerequisites: Docker · Estimated time: 30 min
Your first automatable load test.Hands-on #
Guided steps, with their solutions.
1. Start the target API
Why? httpbin provides predictable routes: normal, slow or error responses on demand.
Run httpbin in a dedicated Docker network.2. Write the script
Why? A minimal test: 10 VUs for 30 s on a simple route.
Createsmoke.jsthat callshttp://httpbin/getwith a check on the status.3. Add thresholds
Why? Thresholds turn a measurement into a verdict: the test fails if the objective is not met.
Add the thresholds: fewer than 1% failures, p95 under 200 ms. Run it again and note the exit code.4. Make the test fail
Why? Checking that a test can fail is as important as seeing it pass.
Replace the route with/delay/1(1 s response). What happens?5. Read the summary
Why? Knowing how to read each line avoids hasty conclusions.
Note downhttp_reqs,http_req_duration(avg, p95),iterationsandchecks. Why is the throughput around 10 requests per second?
Difficulty level : ●○○○○ (1/5)
My progress
Sign in to track your progress and take notes. Sign in
Recommended Articles
Tests de charge avec Grafana k6 : pourquoi et quels types de tests
Pourquoi tester la performance avant la production, les types de tests (smoke, charge, stress, pi...
Écrire des scripts k6 : requêtes, vérifications, scénarios et exécuteurs
La structure d'un script k6 (init, setup, default, teardown), les requêtes HTTP, les checks, les ...
Seuils, métriques et résultats d'un test k6
Lire le résumé d'un test k6, comprendre les métriques intégrées (http_req_duration, http_req_fail...