Abort vuser in K6

How to abort a vuser in K6. We have a scenario in which the user has to be aborted while meeting some particular condition. Knowing the fact that we can abort entire test execution which is not ideal. Is there any possibility? Or is that feature available in future

Hi, @amarnadagera01!

Welcome to our community forums! :tada:

I’m sorry, but I think this isn’t possible for now, as k6 doesn’t officially support a way to abort a concrete VU.

Maybe, you can write some hack that somehow uses context variables (i.e., the VU identifier) to early return on iterations executed on that VU. But, to do that, you will likely need to integrate with Redis to share that knowledge over VUs, as I think in k6 there’s no shared memory among them.
Also, note that this might skew some metrics (like iteration_duration), or affect the whole test execution, depending on what executor you’re using.

So, if you definitely need to, I’d encourage you to try to write that hack. But more generally speaking, I’d discourage that and perhaps try to reshape the testing strategy.

Or is that feature available in future

I’m not sure if there’s any feature request like that (might worth searching over Issues · grafana/k6 · GitHub , and if there’s no one, create one), but I can tell you that nothing like that is in our roadmap, and even if there’s a FR (or you create one), I cannot guarantee we will implement it, because as you can imagine, there’s a lot of nuances to be considered, which are the ones why I’d generally discourage this type of testing strategy.

Anyway, thanks for bringing this, we’re constantly evaluating which are our users needs, so we may eventually consider it. Although, as said, no guarantees, especially in the short term.

:person_bowing:

Thanks @joanlopez for replying. But usually in some scenarios once the test data gets exhausted, ideally user should be ramped down.if not the vuser will start again one more iteration where there will not be any test data present which will lead to failures. For now i have programatically stopping vuser to perform any more iteration(i.e send vuser to loop under infinite while loop with some sleep time in between when vuser tries to get test data post exhaustion).so that user will be active but in ideal condition.Know that it’s not a good solution as such but an interim code which will prevent potential failures. Happy to contribute for this problem for further

Hi, @amarnadagera01 !

Happy to contribute for this problem for further

As said, I cannot make any promise, but I’d like to encourage you to open an issue in Issues · grafana/k6 · GitHub, as a feature request (if none existing for that yet), and even, if you’re willing to, open a pull request to implement that.

If you do so, please be careful as there’s many considerations to have in mind, like correctly implementing that in all executors supported, meaningfully.

The team won’t review the pull request if its quality isn’t par with the requirements. But contributions are welcome, of course! I’ll be so glad to see yours!

Cheers!