I have defined the locale variable in init function and displaying the value in init & default function. Value is getting changed in default function as init function is getting executed multiple times.
Output:
INFO[0001] Init= fr_fr source=console
INFO[0001] CSV_Prod= fr_fr source=console
INFO[0001] CSV_SDP= fr_fr source=console
execution: local
script: .\csv_locale.js
output: -
scenarios: (100.00%) 1 scenario, 1 max VUs, 10m30s max duration (incl. graceful stop):
* default: 1 iterations for each of 1 VUs (maxDuration: 10m0s, gracefulStop: 30s)
INFO[0001] Init= fr_be source=console
INFO[0001] VU: 1 - ITER: 0 source=console
INFO[0001] RandomProduct from fr_be= 0641939001 source=console
Yes I have script with shared array which need to be declared in INIT function. I am using same variable in shared array(INIT) and group(export default function), value of variable is getting changed due to multiple execution of init function.
Again the init is executed once per each VU that needs to initialized. There is no way that we can have a VU without running it’s init context and there are no variables in the init context of a VU before we run the init context.
I would suggest that you try to show how this is breaking something for you with a some full example - it can be a much smaller version of your real script.
Refer output mention above.
locale value is getting changed in export function from init function. The cause of this is multiple execution of init function resulting to multiple value of locale, export function is taking the latest value of locale.
This is not true though. The init context is executed multiple times, sure, but only once in every VU Every VU is just an independent JavaScript runtime, it has its own scope and variables and context. And, for a VU to be initialized, it needs to execute the global scope (the so called “init context”). So the exported default function will use the value of locale that was initialized in the init context of that VU.