Execute extension only once

Hi guys,

im trying to do something like this

but the selection message appears multiple times.

Do you know how I can get it to only run once?

thanks

Hey Juandavid, welcome to the forums o/
Unfortunately, due to the fact you didn’t give a sample of code you are currently using, I would only suggest to place execution of extension to setup() block of code, instead of global scope init() or VU code default function()
If that’s not the case and you are using setup(), please provide some code you are using, so k6 team or me can investigate further.

Here is the documentation about test lifecycle and “what executes when and how many times” :slight_smile:

Also, k6 scripts can’t accept input in this way, you can’t read user keypresses. You need to make this selection happen outside of k6, with something like a shell script wrapper, and then pass the selection to k6 via an environment variable. Alternatively, you can use an xk6 extension: https://k6.io/blog/extending-k6-with-xk6/

Ah, sorry, I missed the post title and the fact that you’ve already written an extension… :man_facepalming:

I suggest you use something like sync.Once in your extension so that the dialog is shown only once, in the initial init context execution that k6 makes to get the exported script options.

Edit: I also moved your post to the Extensions forum category

Hey guys,

thanks for answering.

unfortunately with sync.Once it did not work for me because it is only executed once and as they are different routines I lose the values ​​entered by the user.

luckily i found the solution and i think it would be very useful for k6 project.

Is it possible to contribute to the project with this extension?

Hi @juandavid, you can certainly make it public and open issues with your ideas why something, in particular, will be useful, but at least at the moment having scripts block on user input isn’t one of the things that at least I think is a good idea for the project as most of the use cases for k6 currently are to be automatic tests and having them block on user input is making them not automatic and will have problems in the distributed case. But an extension is perfect for a use case where some users will want this, but we can’t or don’t want to support it in the core product. But this doesn’t mean that both others don’t think differently, and you should definitely publish the extension if that is possible :slight_smile:

1 Like

Hello there,

It is easier than it seems to be.

image

in distributed load tests I pass the parameters through -e and the prompt does not appear.

works fine with helm and k6-operator.

For those who find it useful, they can solve it with mutex and atomics in go.

Thank you