Share data between two scenarios in K6

Hi @rakeshsukla53,

There is no way to share a writable state between VUs. This is unlikely to change soon as there conceptual problems with distributed execution that will need to be fixed IMO before we even try it.

Depending on you use case you can:

  1. use an HTTP server/application to save what you want from the end of funcA and get it at the beginning of funcB - this is by far the most future proof solution, but requires an external tool
  2. you can write your own xk6 extension as long as you won’t run in the cloud. I have shown how to do it with an ever-increasing counter - you can do something more with that if you want to. This is also fairly future proof, but also requires some coding in golang and using xk6 which means it won’t work in the cloud
  3. VUs are reused between scenarios if possible which means that if you fiddle enough with the times and gracefulRampDowns/gracefulShutdowns you can have the same VUs executing both funcA and funcB. At which point you can use their global scope to share state. This probably is the “easiest” solution, but have the limitation that you need to have the same number of VUs and if you at any point change any of the numbers in one scenario - you will need to touch the others. Also while unlikely there is none zero chance that k6 in the future might decide not to work like that, this is after all an implementation detail, even if one that we tried and made happen.
    A good example is shown in this comment that shows how to have a per VU setup and teardown like phase, with the caveats explained above.
  4. depending on what you exactly want to do it is very possible that you can forgo the whole scenarios and just have 1 VU that does them all … even in a single iteration. This of course depends on what you mean by “functional tests”

Hope this helps you, also look at this comment about httpx which is now having some documentation being added, it might be useful for your functional tests.