Per Scenario Init

I have a joined a number of separate k6 tests together using the new scenario feature however I would like to execute different init code depending on the scenario being executed.

This is because several of these scenarios are loading large data sets. I’m using the pattern that @mstoykov shared here to load a sub-set of the data per VU in order to keep the memory usage down, however without the ability to switch by the scenario being executed, all the init code for all my scenarios are being executed.

Is there some reference to the scenario being executed that I can use to test which init code to execute?

Having per-scenario init/setup() will be quite tricky to do right, as me and @mstoykov recently explained in setup() per scenario · Issue #1638 · grafana/k6 · GitHub

Though in your case, given the fact that you’re dealing with large files, maybe the proper solution actually different. Depending on your use case, you might benefit from some of these issues:

It’s still early to tell, so don’t take this as a promise, but there are very good chances that at least the first issue (shared read-only memory) will be implemented in k6 v0.30.0 (the k6 version after next), so in ~3 months from now.

1 Like