[Gatling2] randomSwitch in scenario

Hi!

I have scenario with multiple payments. My scenario ends with
[…]
.randomSwitch(
10 → exec(ScenarioPayments1.chain_payment1),
10 → exec(ScenarioPayment2.chain_payment2),
20 → exec(ScenarioPayment3.chain_payment2),
10 → exec(ScenarioPayment4.chain_payment4),
20 → exec(ScenarioPayment5.chain_payment5),
20 → exec(ScenarioPaymen6.chain_payment6),
10 → exec(ScenarioPaymen7.chain_payment7)
)

}

setUp(
scn_payments.inject(
atOnce(101 users)
).protocolConfig(httpConf)
)
}
But seems, that all users do all payments without any random. So they all do first payments, than second and etc.
Does randomSwitch works in Gatling2 ???

When i tested with Gatling 1.5 randomSwitch works perfectly.

Gatling-2M3a ?

I use Gatling 2M1

In master this works as expected it seems

Stefan

I try one more time. No success
My scenario

val scn_payments = scenario(“Stress test Payments”)
.feed(Users)
.repeat(1) {
exec(ScenarioLogin.chain_login)
.pause(500 milliseconds)
.exec(chain_transfer_type)
.pause(500 milliseconds)
.exec(ScenarioPayments1.chain_payment1)
.pause(500 milliseconds)
.exec(ScenarioPayment1.chain_payment2)
.exec(chain_logout)
.randomSwitch(
exec(ScenarioPayments1.chain_payment1),
exec(ScenarioPayment1.chain_payment2)
)
}

setUp(
scn_payments.inject(
atOnce(6 users)
).protocolConfig(httpConf)

But in test 6 users do payment1 and than same 6 users do payment2
I expect, that 6 user will login on site, 3(or 4, 0or2) will do payment1, and other 3 will go straight to payment2

Stefan Magnus Landrø |





14:04 (3 ч. назад)
|

  • | - |

Перевести сообщение на русский

In master this works as expected it seems

Stefan

Hi,

I don’t get it: you execute payment1 and payment2, both directly and inside a randomSwitch, so users will do payment1, then payment2, then 50/50 payment1 or payment2 (and I expect those to fail as the users have just logged out).

Are you sure you don’t want:

val scn_payments = scenario(“Stress test Payments”)
.feed(Users)
.repeat(1) {
exec(ScenarioLogin.chain_login)
.pause(500 milliseconds)
.exec(chain_transfer_type)
.pause(500 milliseconds)
.randomSwitch(
exec(ScenarioPayments1.chain_payment1),
exec(ScenarioPayment1.chain_payment2)
)
.exec(chain_logout)
}

This is exactly, that I want
Thank You!
facepalm

Also, I’m not really sure why you have an enclosing repeat(1){} block ?

cheers
Nicolas

I migrate this scenario from Gatling 1.5
I change repeating times from test to test.

I’m still very novice in scala, that is why I really need help with randomSwitch in my test

I have test scenario:

.feed(Users)
.repeat(5) {
exec(ScenarioLogin.chain_login)
.pause(500 milliseconds)
.randomSwitch(
exec(ScenarioPayments1.chain_payment1),
exec(ScenarioPayments2.chain_payment2),
exec(ScenarioPayments3.chain_payment3),
exec(ScenarioPayments4.chain_payment4),
exec(ScenarioPayments5.chain_payment5),
)
.exec(chain_logout)
}

In this scenario 100 users do 100 payments, so each user do 1 payment.
Is there any possibility, that each user will do all 5 payments, but in random sequence. So each user after login will do 5 payments in random sequence and logout.

Is there possibility, where I can tell, that each user have to make 3 random payment during one session.

Hi,

First of all, you don’t have to write “exec(ScenarioPayments1.chain_payment1)”, ScenarioPayments1.chain_payment1 is probably already a chain and would be enough.

Hadn’t thought of this use case, so there’s no immediate built in, but definitively doable.
Do you want distinct payment types?

Stéphane

Thank You, Stéphane, for Your quick response!

Yes, I would like, that each payment is called one time by the user and every user call all 5 payments in random order

OK.
We’ll add some built-ins for this, but until then, things will be a bit verbose :

import scala.concurrent.forkjoin.ThreadLocalRandom
import scala.util.Random

// set into the session a “choices” attribute that’s a random sequence of 5 unique indices
.exec(_.set(“choices”, new Random(ThreadLocalRandom.current).shuffle(Seq(0, 1, 2, 3, 4))))
// loop over choices
.foreach("${choices}", “choice”) {
doIfEqualsOrElse(0, “${choice}”) {
chain1
} {
doIfEqualsOrElse(1, “${choice}”) {
chain2
} {
doIfEqualsOrElse(2, “${choice}”) {
chain3
} {
doIfEqualsOrElse(3, “${choice}”) {
chain4
} {
chain5
}
}
}
}
}

Get it?

Stéphane