Setting variables based on __ENV

Hi all,

i’ve a URL variable that I read from a json file and use in my testing.

What I want to do if pass a __ENV variable and overwrite it at run time.

Adding the following code in the default function works, adding it to the setup function does not :frowning:

While it does work it seems I’ll be executing that code a lot and would prefer to do it just the once.

Any tips on how to do what I

const urlIs = __ENV.APIURL;
var url = null;
if(typeof urlIs === 'undefined'){
    url = url_options[0].url;
} else {
    url = urlIs;
systemUrlPort = "https://" + url + ":443";
console.log("systemUrlPort: " + systemUrlPort);

Hi @BobRuub,

I would mostly recommend moving all of this code in the init context - it will be ran once per VU and that should be good enough.

All VUs execute in totally separate JS VMs so there is no writable shared data (at the moment at least). setup is also executed in a separate VM which means that w/e you do in it won’t be seen by the other VUs. The only thing that is being copied is the returned value of setup and each VU gets a copy as the first argument to the default function. Some docs

Hope this helps you

works a treat, should’ve sorted that myself.