Hi , I m new to Gatling. I need to run the scenario based on user’s input condition. I m using Aslongas but m facing the error, where the scenario is running continuously does not stop when it meets the condition.
val count = new java.util.concurrent.atomic.AtomicInteger(0)
val epicScenario = scenario("scenario").feed(userFeeder)
.asLongAs(count.getAndIncrement() <= 3) {
exec(LoginFlow())
.exec(Actionflow)
.exec(session =>
session.set(count,count+1)
)
}
Kindly help with the above one, If anyone have an idea.
Hi,
“count.getAndIncrement() <= 3” is executed only once. Being true the first time, it stays true for ever.
A solution could be to make sure it is evaluated each time by making it a function : session => count.getAndIncrement() <= 3
However, if you only intend to loop multiple times, you might find the usage of repeat simpler:
.repeat(n) {
exec(LoginFlow())
.exec(Actionflow)
}
Thanks Guillaume. I have got it with the below code:
val scn = scenario("scenario").feed(userFeeder)
.exec { session => session.set("counter", 0) }
.asLongAs(condition = _ => counter.getAndIncrement() < Config.NUM_USERS, exitASAP = false) {
exec(LoginFlow())
.exec(Actionflow)
}
Thanks
Bala