hey guys, when I use __VU in code, K6 always throws SyntaxError when compile the script. Debuged for many times, can not find the cause of the error.
Is it because __VU is used inappropriately in script?
Anyone can tell me the reason for the error?
The error is exactly where the >
and ^
symbols indicate it is
You cannot just declare const something;
, you need to assign some value to the constant when you create it, e.g. const foo = 'bar';
, see const - JavaScript | MDN
Use the var or let if you want to declare a variable early and assign its value later.
After declaring variables, k6 throwed TypeError: Assignment to constant variable.
Please read through the links in my previous post, specifically const - JavaScript | MDN
const
means it’s constant, that’s the whole point…
value of a constant can’t be changed through reassignment (i.e. by using the assignment operator), and it can’t be redeclared
Sorry @ned , I’m not very familiar with JS, if i set the variables to let type, how to reference variables in get_body function.
I have no idea what you are trying to do here…
But if you assign values to these variables only in some VUs (because of the if (__VU == 0)
, if (__VU == 1)
, etc. conditions), then it’s expected that they will not have value in the other VUs. Every VU will execute your script code independently, and with these checks you are making some VUs fail, since they don’t have any value for jsonData_X
.
Please spend some time reading through the documentation and trying to understand how k6 works. Your current script is nonsensical to me, so I can’t help you. I can’t also write your test for you, screenshotted error by screenshotted error, sorry…
Sorry for the late reply @ned ,I solved the problem successfully,thanks your pointer.