Quick and painless load testing for Elixir applications. Generate and run load tests via a local installation of k6.
Originally developed at SpawnFest 2021.
The package can be installed by adding k6
to your list of dependencies in mix.exs
:
def deps do
[
{:k6, "~> 0.2.1"}
]
end
To generate new k6 tests run:
mix k6.gen.test <test_name>
By default k6 tests will be placed under the priv/k6
directory of your project.
The template to use for the test can be set via the --type
argument.
Supported types are rest
(default), graphql
, grpc
, websocket
, phoenix-channel
(experimental) and liveview
(experimental).
Run mix help k6.gen.test
for more info on generating tests.
To execute k6 tests run:
mix k6 run <test_name>.js
Run mix help k6
for more info on running k6.
elixir-k6
can be configured via config.exs
as follows:
config :k6,
version: "vX.Y.Z",
env: [VAR_KEY: "some value"],
workdir: "priv/my_load_tests_dir"
The supported configuration parameters are:
version
: the desired version of k6. Defaults tov0.39.0
.env
: environment variables to pass to load tests. K6 will expose those variables to load test scripts within the__ENV
object.workdir
: path of the directory that contains k6 load tests. Relative to the project, defaults topriv/k6
.
K6 is automatically installed the first time you run k6 tests, and it is stored in _build/k6
.
In case you want to explicitly install it before running any test, you can run mix k6.install
.
At the moment the following architectures are supported:
OS | Architecture |
---|---|
MacOs | amd64 |
MacOs | arm64 (not tested) |
Linux | amd64 |
Linux | arm64 (not tested) |
By default the installation task will install k6 version v0.39.0
.
You can override this in your config file, as documented above.
Issues and contributions are welcome!
To run static analysis run:
mix check
To execute tests run:
mix test
The test suite also includes some end-to-end tests, which are not executed by default as they are much slower. To execute all tests run:
mix test --include end_to_end