Posting this question here because I saw this being asked from years ago and was unanswered.
I was under the impression that randomSwitch was used to specify the percentage of load (from testSetup injection) that you want to send to a specific request or group.
The code I wrote for the randomSwitch looked like this:
.randomSwitch().on(
Choice.withWeight(40.0, exec(StudentLoginStartSubmitFlow)),
Choice.withWeight(60.0, exec(doSomethingElse))
)
The expectation was that exactly 40% of the initial load (10) would hit the StudentLoginStartSubmitFlow endpoint. I.e. 40% of 10 = 4 users hitting this every run.
The results fluctuated. Sometimes they were as expected, others it was lower or higher.
Is randomSwitch used to declare the exact load to inject or is it used to specify a probability in which the StudentLoginStartSubmitFlow endpoint will be triggered, hence the fluctuating results.
If the latter is true, is there a way to perform the former?
CodePudding user response:
As name states, randomSwitch
is based on a random generator, so you can expect neither a predictable distribution nor a perfect one, particularly at such a low load.
If you want to achieve perfect and predictable distribution, you'll have to use a doSwitch
block and pass your own algorithm, eg based on a global AtomicInteger incremental counter.
You'll probably realize that it's pretty complicated once you're not with the easy case of 40% of 10 but have to deal with 37% of 128 :)
If you stick to simple cases, using a modulo might work for you.