Test user creation run to json/csv

We want to prepare users by running through complex registration flow using k6 scenario, and storing customerid, email and creds in json or csv.

I imagine this is a pretty common usecase, but I can only find examples of loading data from a file.

I was hoping I could update the SharedArray from the scenario for every created customer, and storing it in handleSummary(). unfortunately it’s immutable.

How do you normally do this? There must be a better way than logging the data in console and parsing after the run.

Hi @miklesw

Welcome to the community forum :wave:

As you point out, the SharedArray is just for reading. It’s shared between virtual users (VUs) and optimized for reads. You are able to read the data to create the users (email, etc.), but you can’t store back the customerid and other data your system under test (SUT) returns.

Consider using a database extension, e.g. GitHub - grafana/xk6-sql: k6 extension to load test RDBMSs (PostgreSQL, MySQL, MS SQL and SQLite3), to store the results of each iteration. Or at the end of the test in the teardown() phase, if it’s not a lot of data and won’t impact memory usage.

You can have a look at how to load test a database, as an example of how to use a database extension. You can use this to read or store data for tests, instead of load testing the database. This option can also help if you ever have the need to run distributed tests.

If you can provide more context we might be able to better advice. For example, do you want to keep the customerid for a clean-up after the test only? What is the use for the data you store from the test?

I hope this helps.


Creating customers/users can be quite a long and complex processes affecting multiple systems. So you wouldn’t want this to be part of your load test.

You would want to register new customers beforehand, and assign a customer per VU during load test.

K6 team is considering allow network connectivity from SharedArray or provide another Shared data object for this use case

1 Like