Hi all, I’m looking something like randomSwitch() in Gatling, actually I’m planning to migrate from Gatling to K6.
Let say I have a user who login to the system, then searching other people, vehicles, locations, etc. But I want that user search people in first iteration, and search vehicles or locations (randomly) in second iteration, and so on. Could you please help?
Thanks in advance!
Thanks for reaching out! From what I understand of what you’re trying to achieve, and of Gatling’s
randomSwitch() mechanism, it sounds like you should be able to perform that through scripting directly. We unfortunately don’t have pre-existing APIs to do just that yet, but this discussion might help you achieve what you’re looking for.
Let me know if that’s helpful and if I can help you any further.
hi @oleiade , thanks for your information. Actually I’m implementing the approach that you mentioned in the link. I just works, but it would be great if K6 team can implement an API for this
Glad I could help, and that you’ve found a solution addressing your problem!
Your post actually triggered a discussion internally, and although we can see the value of such a feature, building something meaningful enough and an API that’s both generic and specific enough to be used in the variety of scenarios we encounter appears tricky.
If you have ideas on the topic, we’d be glad to receive and review a PR from you on the topic. If you’re interested, we have a dedicated tutorial on how to build k6 extensions.
weightedSwitch() function can be implemented fairly simply in the thread @oleiade linked to, and that seems fairly similar to
randomSwitch : How to distribute VU's across different scenarios with k6 - #17 by nedyalko
So this maybe something more appropriate for https://jslib.k6.io/, not an extension?