k6 v0.36.0 is here! 🎉 It introduces a couple of new features which enhance its usability, includes a number of fixes, and the result of ongoing refactoring efforts.
Source Maps support (#2082)
Following #2082, k6 now has support for Source Maps. k6 will try to load source maps either from the file system(s) or from inside the script, based on the standard(-ish) //#sourceMappingURL=
comments. Furthermore, as k6 internally uses Babel to transform ES6+ scripts to ES5.1+, it will now make use of its ability to generate source maps, including combining with previously generated ones, to report correct line numbers. This should fix #1804; however, we anticipate some more issues will arise, and further tweaking will be necessary.
Thus, given an imported.js
module such as:
export function f1() {
throw "line 2";
}
throw "line 6";
}
export function f3() {
throw "line 10";
}
and a k6 test script importing it as such:
import { f2 } from "./imported.js"
export default function() {
f2();
}
Previous versions of k6 would report an error stack trace indicating an invalid line number in imported.js
(10):
ERRO[0000] line 6
at f2 (file:///some/path/imported.js:10:61(2))
at file:///some/path/sourcemap.js:4:20(4) executor=per-vu-iterations scenario=default source=stacktrace
Starting with v0.36.0
and source maps support, k6 would now report the exception at the correct line in imported.js
:
ERRO[0000] line 6
at f2 (file:///some/path/imported.js:6:2(2))
at file:///some/path/loadtest.js:4:2(4)
at native executor=per-vu-iterations scenario=default source=stacktrace
Note that if a file size is greater than 250kb and the internal Babel is needed, Babel will not generate source map. This is because during internal testing it was found this takes 3x to 4x more memory, potentially leading to OOM (standing for "Out Of Memory", a state in which the OS kills a process for using too much memory) on bigger inputs. If required, you can control the accepted file size limit via the temporary K6_DEBUG_SOURCEMAP_FILESIZE_LIMIT=524288
environment variable; which will be removed after we no longer rely on Babel (#2296). A pre-generated source map will always be loaded. For more details, check #2345.
Ability to abort tests (#2093)
Thanks to the contribution of @gernest (#2093), k6 now has the ability to abort a test run from within the test script. The newly added test.abort()
function in the k6/execution
module allows k6 scripts to immediately abort the test execution - the VU that called it will abort immediately and any other VUs in the same or other instances (in the case of k6 cloud
) will also be interrupted and abort soon after. Local k6 run
tests will exit with a code of 108
, so this event can also be easily detected in a CI script.
Aborting is possible during initialization:
import exec from "k6/execution";
exec.test.abort();
As well as inside the default function:
import exec from "k6/execution";
export default function() {
// Note that you can abort with a specific message too
exec.test.abort("this is the reason");
}
export function teardown() {
console.log("teardown will still be called after test.abort()");
}
k6 inspect extended output (#2279)
Following #2279, the k6 inspect
command now supports an --execution-requirements
flag. When used, the command's output will include fields related to the execution requirements, by deriving k6's configuration from the execution context, and including the maxVUs
and totalDuration
fields in the output.
Forcing HTTP/1 protocol (#2222)
Thanks to the work of @sjordhani22, #2222 made it possible to force k6 to use version 1.1 of the protocol when firing HTTP requests.
It can be done by setting the http2client=0
value in the GODEBUG
environment variable:
GODEBUG=http2client=0 k6 run testscript.js
N.B: the usage of the GODEBUG
variable is considered temporary, and expected to change in the future. If you start using this feature, keep an eye out for potential future changes.
v0.36.0
marks the switch of some of our internal modules to a new Go/JavaScript module API. We expect this change to make the process of developing internal JavaScript modules and advanced JavaScript extensions easier and more streamlined in the future. Although this switch to a new API does not introduce breaking changes for existing extensions yet, we anticipate deprecating the old extension API (e.g. common.Bind()
, lib.WithState()
, etc.) at an undecided point in the future.
For more details, see: #2243, #2241, #2239, #2242, #2226, and #2232.
VUs are now restricted to only open()
files that were also opened in the init context of the first VU - the one that was initialized to get the exported options
from the JS script (__VU==0
). While it was somewhat possible to open files only in other VUs (e.g __VU==2
) in the past, it was unreliable. #2314 ensures that k6 would now throw an error in a similar scenario. This means that you can still open files only for some VUs, but you need to have opened all of those files in the initial VU (__VU==0
).
let file;
if (__VU == 0) {
open("./file1.bin")
open("./file2.bin")
} else if (__VU % 2 == 0) {
file = open("./file1.bin")
} else {
file = open("./file2.bin")
}
export default () => {
// use file for something
}
- We addressed an issue uncovered by our community, which kept our users from using GRPC with multiple services definition in a single proto file. This issue was solved in #2265.
- Thanks to the contribution of @Resousse, we've now updated k6's
go-ntlmssp
dependency. The updating PR #2290 indeed fixes issues with NTLM Authentication backends returning two authorization headers.
- We have refactored our implementation of the RampingVU executor, for better clarity and maintainability. See #2155.
- #2316 relaxed quite a few of the code linting rules we applied to k6's code. It also revamped our Makefile, so the new
make ci-like-lint
target will run the exact same golangci-lint version that will be used in our GitHub Actions CI pipeline. - #2304 prepared the removal of external dependencies from k6's JSONAPI compliant REST API, and deprecated the
api.v1
'sclient.Call
method in favor of its newerclient.CallAPI
counterpart. It allows us to both reduce our reliance on external dependencies and improve its maintainability. - We have updated our Goja dependency, our JS interpreter, to its latest available version. Unfortunately, some of the new features are not always usable, yet. Namely, Goja now supports the optional chaining syntax, but the Babel version we use presently does not. Which means that if Babel needs to be used, optional chaining can't be. See #2317 and #2238.
- Thanks to @knittl, #2312 upgraded loadimpact/k6 docker image base to Alpine 3.15.
- #2226 introduced an unintended breaking change to
http.head()
. The signature in k6 v0.35.0 washttp.head(url, [params])
and was inadvertently changed tohttp.head(url, [body], [params])
in v0.36.0. That change will be reverted in k6 v0.37.0, but until then, we suggest users use the stablehttp.request('HEAD', url, null, params)
API for HTTP HEAD requests that need to specify custom parameters. Thanks, @grantyoung, for reporting the problem (#2401)!