Loading Test data?

Hi @mercfh

As mentioned in Is JSON.stringify() necessary for payloads via Shared Array? - #7 by immavalls2, it’s a good option to go for a SharedArray. You need to wait until we implement SharedArray improvements · Issue #2043 · grafana/k6 · GitHub to be able to move reading the file to the setup function, where it would only be read once.

If you need to to use different values, data parameterization is the way to go. And SharedArray will take care of this being optimal. Under performance characteristics we describe a bit more the gains.

In terms of where k6 users use setup and teardown, you can find some examples in https://github.com/grafana/k6-learn/blob/main/Modules/III-k6-Intermediate/07-Setup-and-Teardown-functions.md#setup. Some concrete examples:

  • Obtain an authentication token in the setup and have all VUs use it. In situations where you are not testing the token/authentication endpoint, but your API endpoints. E.g. Unique login for each virtual User - #3 by immavalls2
  • When you want to test the system that needs some previous data loaded, that is not part of the test. You can create the data using the setup and delete it in the teardown. E.g. with the sql extension, create records in a database that will be used in the test, and then delete the records at teardown to leave the system as it was.

In the setup function you can use most k6 APIs, just not open a local file at this time.

I hope this helps clarify.

Cheers!