“k6 is an open-source load testing tool”
The k6 documentation is amazing and a massive shout out to Chris Alwin James for his github examples and YouTube video.
Useful links
- https://test-api.k6.io/
- https://k6.io/docs/using-k6/http-requests/
- https://k6.io/docs/using-k6/environment-variables/
- JSON Parse
- Debug http
- File upload
Test life cycle
1 | // 1. init code |
Terminology
- VU (Virtual User), an entity that executes a test and makes requests. These are run concurrently and repeat the test over and over.
- Checks, are like asserts but differ in that they dont halt execution.
- Thresholds, are global pass/fail criteria for k6 to use, this can fail a load test.
Types of tests
1 | //baseline |
Metrics & Example test
- Counter - A metric that cumulatively sums added values.
- Gauge - A metric that stores the min, max and last values added to it.
- Rate - A metric that tracks the percentage of added values that are non-zero.
- Trend - A metric that allows for calculating statistics on the added values (min, max, average and percentiles).
1 | import http from "k6/http"; |
Understanding the metric results
The following are results based on simple-poll.test.js with status percentage set at 0.1
and 0.9
1 | -------------- status percentage 0.1 |
Looking at status percentage 0.1
results its a little confusing as the ✗
are the passes and the ✓
are the failures (except for the checks metric!)
Built-in metric
Metric name | Comments |
---|---|
checks | |
http_req_duration | |
iterations | |
http_reqs | Difference in iterations and http_reqs |
Custom metric
Metric name | Comments |
---|---|
foo_error_count | |
foo_error_rate | |
foo_gauge | |
foo_trend |
Extensions & Typescript support
k6 Browser Recorder can be used to simulate load and generate a baseline test.
JS is great but type safety is great(er) :D